Tip of the day - JavaScript

Un trucchetto al giorno per mantenerti allenato o per conoscere qualcosa di nuovo sul magico mondo di JavaScript.

88

Console placeholders

2021-05-27 - JavaScript

1// JS Tip of the Day
2// Console placeholders
3
4const hero = { name: "Batman", weapon: "Batarang" };
5console.log('Hi %s! You are %i years old! Wooooooah!',  hero.name, 81);
6// Hi Batman! You are 81 years old! Wooooooah!
7
8console.info('Hi %s! Your object is %o',  hero.name, hero);
9// Hi Batman! Your object is {name: "Batman", weapon: "Batarang"}
#JStipoftheday
87

Asyncronous Script Loading with Async and Defer

2021-05-25 - JavaScript

1// JS Tip of the Day
2// Asyncronous Script Loading with Async and Defer
3
4
5<!-- executed before window.load / no order matter / HTML Parsing Paused -->
6<script async src=”myAsyncScript.js” onload=”myAsyncInit()></script>
7
8<!-- executed before DOMContentLoaded / order matter / Execution after HTML Parsing --> 
9<script defer src=”myDeferScript.js” onload=”myDeferInit()></script>
#JStipoftheday
86

Simple Code Generator

2021-05-24 - JavaScript

1// JS Tip of the Day
2// Simple Code Generator
3
4const code = Math.random().toString(36).substring(2);
5console.log(code); // e.g. f3bkxjlpcbp
#JStipoftheday
85

How to detect when speech through the device's microphone

2021-05-21 - JavaScript

1// JS Tip of the Day
2// How to detect when speech through the device's microphone
3
4window.SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition;
5
6const recognition = new window.SpeechRecognition();
7recognition.continuous = true;
8
9recognition.onresult = (event) => {
10	const speechToText = event.results[event.resultIndex][0].transcript;
11    console.log(speechToText.trim());
12}
13
14recognition.onerror = (event) => {
15    // ...
16    if (event.error == 'not-allowed') {
17      console.log('fine');
18    }
19} 
20
21recognition.start();
#JStipoftheday
84

Get voice/speech from text with Web Speech API

2021-05-20 - JavaScript

1// JS Tip of the Day
2// Get voice/speech from text with Web Speech API
3
4if('speechSynthesis' in window){
5     const heroSpeech = new SpeechSynthesisUtterance('I\'m Batman!');
6     heroSpeech.lang = 'en-US';
7     window.speechSynthesis.speak(heroSpeech);
8 }
9
#JStipoftheday

Preferisci ricevere i tips via mail? Iscriviti alla newsletter.

Iscriviti alla newsletter

Tip of the day - JavaScript

Hai in mente un progetto e vorresti realizzarlo?
Sei interessato a migliorare le tue competenze o quelle del tuo team in ambito di programmazione e sviluppo?

Anche se - semplicemente - vuoi prendere un caffè con noi o vedere la nostra collezione di Action Figures scrivici tramite questo form.

Questo sito è protetto da reCAPTCHA e si applicano le Norme sulla privacy e i Termini di servizio di Google.