← 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-03-12
1// JS Tip of the Day
2// Check if all Array item passes a condition
3
4const heroes = [
5 { name: "Batman", superPower: "money", team: 'Justice League' },
6 { name: "Superman", superPower: "flight", team: 'Justice League' },
7 { name: "Wonder Woman", superPower: "superior strength", team: 'Justice League' }
8];
9
10const haveMoney = heroes.every(hero => hero.superPower === 'money');
11console.log(haveMoney); // false
12
13const bestTeam = heroes.every(hero => hero.team === 'Justice League');
14console.log(bestTeam); // true
2021-03-11
1// JS Tip of the Day
2// Improve readability with Numeric Separator
3
4const anIntegerNumber = 5_667_441;
5console.log(anIntegerNumber); // 5667441
6const aFloatNumber = 3.14159_26535;
7console.log(aFloatNumber); // 3.1415926535
8
9const aBinaryNumber = 0b101_0110_0111_1010_0111_0001;
10console.log(aBinaryNumber); // 5667441
11const anHexNumber = 0x0056_7A71;
12console.log(anHexNumber); // 5667441
13
14const aVeryBigNumber = 1e1_2;
15console.log(aVeryBigNumber); // 1000000000000
16
17// Don't do it!
18const anotherVeryBigNumber = 1e_12; // It's an error!
19const anotherFloatNumber = 3._14159_26535; // It's an error!
2021-03-10
1// JS Tip of the Day
2// Check if at least one Array item passes a condition
3
4const heroes = [
5 { name: "Batman", superPower: "money" },
6 { name: "Superman", superPower: "flight" },
7 { name: "Wonder Woman", superPower: "superior strength" }
8];
9
10const haveMoney = heroes.some(hero => hero.superPower === 'money');
11console.log(haveMoney); // true
2021-03-09
1// JS Tip of the Day
2// Remove properties from an Object
3
4const hero = { name: 'Batman', weapon: 'Batarang', vehicle: 'Batmobile', partner: 'Robin' };
5
6// Dot or Array notation way
7delete hero.vehicle;
8delete hero['partner'];
9console.log(hero);
10// { name: "Batman", weapon: "Batarang" }
11
12// Immutable way with rest operator
13const anotherHero = { name: 'Batman', weapon: 'Batarang', vehicle: 'Batmobile', partner: 'Robin' };
14const { partner, ...restHero } = anotherHero;
15console.log(restHero);
16// {name: "Batman", weapon: "Batarang", vehicle: "Batmobile" }
17
18// Immutable way with rest operator and dynamic property
19const prop = 'vehicle';
20const { [prop]: exclProp, ...anotherRestHero } = restHero;
21console.log(anotherRestHero)
22// {name: "Batman", weapon: "Batarang" }
2021-03-08
1// JS Tip of the Day
2// Add properties to an Object
3
4const hero = { name: 'Batman', weapon: 'Batarang' };
5hero.vehicle = 'Batmobile'; // Dot notation way
6hero['partner'] = 'Robin'; // Array notation way
7
8Object.assign(hero, { friend: 'Superman' }); // Object Assign
9console.log(hero);
10// { name: "Batman", weapon: "Batarang", vehicle: "Batmobile", partner: "Robin", friend: "Superman" }
11
12const anotherHero = { ...hero, pet: 'Ace' }; // Immutable way with destructuring
13console.log(anotherHero);
14// {name: "Batman", weapon: "Batarang", vehicle: "Batmobile", partner: "Robin", friend: "Superman", pet: "Ace" }
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.