← 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.

50

Get all form's elements

2021-04-02

1// JS Tip of the Day
2// Get all form's elements
3
4/*
5<form id="hero-form">
6  <input type="text" name="hero-name">
7  <input type="number" name="hero-age">
8  <select name="hero-team">
9  	<option value="JL">Justice League</option>
10    <option value="SS">Suicide Squad</option>
11  </select>
12  <textarea name="hero-bio"></textarea>
13</form>
14*/
15
16// You can use HTMLFormElement.elements
17let formElements = document.getElementById("hero-form").elements;
18// elements methods return an Array-like collection then...
19let formElementsArray = Array.from(formElements);
20
21formElementsArray.forEach(el => console.log(el.name)); 
22// hero-name, hero-age, hero-team, hero-bio
49

Always returns false after the first comparison with Slim Arrow Operator

2021-04-01

1// JS Tip of the Day
2// Always returns false after the first comparison with Slim Arrow Operator  
3
4let a = 0b101010;
5let b = 0b0000000000101001;
6
7console.log(a --> b); // true
8console.log(a --> b); // false
9
10N.B. Happy April Fool!!!! :D
48

Use Array like a Stack (LIFO Mode)

2021-03-31

1// JS Tip of the Day
2// Use Array like a Stack (LIFO Mode)
3
4let heroes = ['Batman', 'Superman', 'Green Arrow', 'Cyborg'];
5arr.push('Flash');  // ['Batman','Superman', 'Green Arrow', 'Cyborg', 'Flash']
6arr.pop(); // ['Batman','Superman', 'Green Arrow', 'Cyborg']
7
47

Use Array like a Queue (FIFO Mode)

2021-03-30

1// JS Tip of the Day
2// Use Array like a Queue (FIFO Mode)
3
4let heroes = ['Batman', 'Superman', 'Green Arrow', 'Cyborg'];
5arr.shift() // ['Superman', 'Green Arrow', 'Cyborg'];
6arr.push('Flash'); // ['Superman', 'Green Arrow', 'Cyborg', 'Flash'];
46

Add a quick breakpoint

2021-03-29

1// JS Tip of the Day
2// Add a quick breakpoint
3
4function getAnHero() {
5    // Invoke a debugger (if one exists)
6	debugger;
7    return 'Batman';
8}
9
10console.log(getAnHero());

Contattaci.

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.

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