Skip to content

Commit be03e66

Browse files
committed
Arrow functions basics, first translation
1 parent 6db4fe9 commit be03e66

File tree

1 file changed

+33
-30
lines changed
  • 1-js/02-first-steps/17-arrow-functions-basics

1 file changed

+33
-30
lines changed
Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
# Arrow functions, the basics
1+
# Arrow functions, le basi
22

3-
There's another very simple and concise syntax for creating functions, that's often better than Function Expressions.
3+
Esiste un'altra sintassi molto semplice e concisa per creare funzioni e che spesso è migliore delle Function Expressions.
44

5-
It's called "arrow functions", because it looks like this:
5+
E' chiamata "arrow functions", perché si presenta in questo modo:
66

77
```js
88
let func = (arg1, arg2, ...argN) => expression
99
```
1010

11-
...This creates a function `func` that accepts arguments `arg1..argN`, then evaluates the `expression` on the right side with their use and returns its result.
11+
Questo codice crea una funzione `func` che accetta gli argomenti `arg1..argN` e li utilizza per valutare `expression` e restituirne il risultato.
1212

13-
In other words, it's the shorter version of:
13+
In altre parole è una versione abbreviata di:
1414

1515
```js
1616
let func = function(arg1, arg2, ...argN) {
1717
return expression;
1818
};
1919
```
2020

21-
Let's see a concrete example:
21+
Vediamo un esempio concreto:
2222

2323
```js run
2424
let sum = (a, b) => a + b;
2525

26-
/* This arrow function is a shorter form of:
26+
/* Questa arrow function è una versione abbreviata di:
2727
2828
let sum = function(a, b) {
2929
return a + b;
@@ -33,32 +33,32 @@ let sum = function(a, b) {
3333
alert( sum(1, 2) ); // 3
3434
```
3535

36-
As you can, see `(a, b) => a + b` means a function that accepts two arguments named `a` and `b`. Upon the execution, it evaluates the expression `a + b` and returns the result.
36+
Come puoi vedere `(a, b) => a + b` rappresenta una funzione che accetta due argomenti `a` e `b`. Al momento dell'esecuzione, questa valuta l'espressione `a + b` e restituisce il risultato.
3737

38-
- If we have only one argument, then parentheses around parameters can be omitted, making that even shorter.
38+
- Se abbiamo un solo argomento, le parentesi che racchiudono gli argomenti possono essere omesse, abbreviando ulteriormente il codice.
3939

40-
For example:
40+
Ad esempio:
4141

4242
```js run
4343
*!*
4444
let double = n => n * 2;
45-
// roughly the same as: let double = function(n) { return n * 2 }
45+
// più o meno lo steso di: let double = function(n) { return n * 2 }
4646
*/!*
4747

4848
alert( double(3) ); // 6
4949
```
5050

51-
- If there are no arguments, parentheses will be empty (but they should be present):
51+
- Se non ci sono argomenti, le parentesi saranno vuote (ma devono essere presenti):
5252

5353
```js run
5454
let sayHi = () => alert("Hello!");
5555
5656
sayHi();
5757
```
5858

59-
Arrow functions can be used in the same way as Function Expressions.
59+
Le Arrow functions possono essere usate allo stesso modo delle Function Expressions.
6060

61-
For instance, to dynamically create a function:
61+
Ad esempio, per creare dinamicamente una funzione:
6262

6363
```js run
6464
let age = prompt("What is your age?", 18);
@@ -70,42 +70,45 @@ let welcome = (age < 18) ?
7070
welcome();
7171
```
7272

73-
Arrow functions may appear unfamiliar and not very readable at first, but that quickly changes as the eyes get used to the structure.
73+
Le Arrow functions possono apparire poco familiari e leggibili all'inizio, ma ciò cambia rapidamente man mano che gli occhi si abitueranno alla struttura.
7474
75-
They are very convenient for simple one-line actions, when we're just too lazy to write many words.
75+
Esse sono molto comode per semplici azioni su una riga, se siamo troppo pigri per scrivere più parole.
7676
77-
## Multiline arrow functions
77+
## Arrow functions su più linee
7878
79-
The examples above took arguments from the left of `=>` and evaluated the right-side expression with them.
79+
Gli esempi precedenti hanno preso argomenti alla sinistra di "=>" e con essi hanno valutato l'espressione a destra.
8080

81-
Sometimes we need something a little bit more complex, like multiple expressions or statements. It is also possible, but we should enclose them in curly braces. Then use a normal `return` within them.
81+
A volte abbiamo bisogno di qualcosa di un po' più complesso, come espressioni o dichiarazioni multiple. Anche questo è possibile, ma dovremo racchiuderle tra parentesi graffe ed usare un
82+
non normale`return`.
8283
83-
Like this:
84+
In questo modo:
8485
8586
```js run
86-
let sum = (a, b) => { // the curly brace opens a multiline function
87+
let sum = (a, b) => { // le parentesi graffe aprono una funzione multilinea
8788
let result = a + b;
8889
*!*
89-
return result; // if we use curly braces, then we need an explicit "return"
90+
return result; // se usiamo le parentesi graffe abbiamo bisogno di un esplicito "return"
9091
*/!*
9192
};
9293
9394
alert( sum(1, 2) ); // 3
9495
```
9596
96-
```smart header="More to come"
97-
Here we praised arrow functions for brevity. But that's not all!
97+
```smart header="Molto di più..."
9898
99-
Arrow functions have other interesting features.
99+
Qui abbiamo presentato le arrow functions in breve, ma questo non è tutto!
100100
101-
To study them in-depth, we first need to get to know some other aspects of JavaScript, so we'll return to arrow functions later in the chapter <info:arrow-functions>.
101+
Le Arrow functions possiedono altre interessanti caratteristiche.
102102
103-
For now, we can already use arrow functions for one-line actions and callbacks.
103+
Per studiarle approfonditamente dobbiamo prima conoscere qualche altro aspetto di JavaScript, quindi torneremo alle arrow functions più avanti, nel capitolo <info: funzioni-freccia>.
104+
105+
Per ora possiamo già utilizzarle per azioni su una riga sola e per callbacks.
104106
```
105107
106108
## Summary
107109
108-
Arrow functions are handy for one-liners. They come in two flavors:
110+
Le Arrow functions sono utili per azioni su una riga sola. Possono essere scritte in due modi:
109111
110-
1. Without curly braces: `(...args) => expression` -- the right side is an expression: the function evaluates it and returns the result.
111-
2. With curly braces: `(...args) => { body }` -- brackets allow us to write multiple statements inside the function, but we need an explicit `return` to return something.
112+
1. Senza parentesi graffe: `(...args) => expression` -- la parte destra è un'espressione: la funzione la valuta e restituisce il risultato.
113+
2. Con parentesi graffe: `(...args) => { body }` -- le parentesi ci permettono di scrivere comandi multipli all'interno della funzione, ma abbiamo bisogno di dichiarare esplicitamente
114+
`return` affichè sia ritornato qualcosa.

0 commit comments

Comments
 (0)