βΒ Torna al blog
Dev Tips
Un trucchetto al giorno leva le complicazioni di torno! Piccole "scorciatoie" che possono facilitare la vita degli sviluppatori e far risparmiare tempo...e righe di codice.
Un trucchetto al giorno leva le complicazioni di torno! Piccole "scorciatoie" che possono facilitare la vita degli sviluppatori e far risparmiare tempo...e righe di codice.
2021-02-12
1// JS Tip of the Day
2// Styling Console Output with %c directive (Modern Browsers)
3
4console.log("%c I'm Batman!", "color: black; background-color: yellow; padding: 2px");
5
2021-02-11
1// JS Tip of the Day
2// Array Intersection
3
4const arrA = [1,2,3];
5const arrB = [2,5,3];
6
7const intersectionArr = arrA.filter(value => arrB.includes(value));
8
9console.log(intersectionArr); // [2,3]
2021-02-10
1// JS Tip of the Day
2// Value to Boolean Conversion
3
4// with Not Not Operator
5console.log(!!false); // false
6console.log(!!true); // true
7console.log(!!0); // false
8console.log(!!parseInt("Batman")); // false because NaN is falsy
9console.log(!!1); // true
10console.log(!!-1); // true -1 is truthy
11console.log(!!(1/0)); // true because Infinity is truthy
12console.log(!!(Infinity)); // true because Infinity is truthy
13console.log(!!""); // false because empty string is falsy
14console.log(!!"Batman"); // true because non-empty string is truthy
15console.log(!!undefined); // false because undefined is falsy
16console.log(!!null); // false because null is falsy
17console.log(!!{}); // true because an (empty) object is truthy
18console.log(!![]); // true because an (empty) array is truthy;
19
20// or use a built-in Boolean function
21console.log(Boolean("Batman")); // true because non-empty string is truthy
22// ...
23
24
25
26
27
2021-02-09
1// JS Tip of the Day
2// Exponential Operator
3
4// Old School
5Math.pow(x, y);
6
7// ...or use ES2016/ES7 exponential operator
8x ** y
2021-02-08
1// JS Tip of the Day
2// String occurrences quick replacement
3
4const heroes = 'π¦ π€ π·οΈ π€ π';
5
6// with RegEx
7const heroesHandshake = heroes.replace(/\π€/g, 'π€');
8console.log(heroesHandshake); // π¦ π€ π·οΈ π€ π
9
10// without RegEx - ES2021/ES12
11const heroesHandshakeReplaceAll = heroes.replaceAll('π€', 'π€');
12console.log(heroesHandshakeReplaceAll); // π¦ π€ π·οΈ π€ π
Hai in mente un progetto e vorresti realizzarlo?
Sei interessato a migliorare le competenze del tuo team in ambito di programmazione e sviluppo?
Oppure vuoi semplicemente prendere prendere un caffè con noi e vedere la nostra collezione di Action Figure, allora scrivici tramite questo form.
Se, invece, vuoi far parte del team, guarda le nostre offerte di lavoro.