Skip to content

Commit f300bd4

Browse files
authored
Merge pull request #175 from javascript-tutorial/sync-3a0b3f4e
Sync with upstream @ 3a0b3f4
2 parents dd5dd39 + 207c87f commit f300bd4

File tree

13 files changed

+61
-44
lines changed

13 files changed

+61
-44
lines changed

1-js/01-getting-started/2-manuals-specifications/article.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@ Inoltre, se state sviluppando in ambiente browser, ci sono ulteriori specifiche
1717

1818
## Manuali
1919

20-
- **MDN (Mozilla) JavaScript Reference** è un manuale con esempi ed altre informazioni utili. E' ottimo per avere informazioni dettagliate riguardo le funzioni e i metodi del linguaggio.
2120

22-
Può essere consultato al link <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference>.
23-
24-
Anche se, è meglio eseguire una ricerca internet. E' sufficiente inserire il termine "MDN" nella stringa da ricercare, e.g. <https://google.com/search?q=MDN+parseInt> per ricercare la funzione `parseInt`.
21+
- **MDN (Mozilla) JavaScript Reference** è il principale manuale con esempi ed altre informazioni utili. E' ottimo per avere informazioni dettagliate riguardo le funzioni e i metodi del linguaggio.
2522

23+
Può essere consultato al link <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference>.
2624

27-
- **MSDN** – Manuale Microsoft con molte informazioni, incluso JavaScript (a cui viene fatto riferimento con il termine JScript). Se si ha bisongo di ottenere qualche informazione specifica per Internet Explorer, meglio consultare la guida: <http://msdn.microsoft.com/>.
25+
Sebbene spesso sia meglio eseguire una ricerca internet, è' sufficiente inserire il termine "MDN" nella stringa da ricercare, e.g. <https://google.com/search?q=MDN+parseInt> per ricercare la funzione `parseInt`.
2826

29-
Possiamo anche effettuare una ricerca online con frasi come "RegExp MSDN" o "RegExp MSDN jscript".
3027

3128
## Tabelle di compatibilità
3229

1-js/03-code-quality/02-coding-style/code-style.svg

Lines changed: 1 addition & 1 deletion
Loading

1-js/04-object-basics/03-garbage-collection/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ Semplicemente una valore "raggiungibile" deve essere accessibile o utilizzabile.
1414

1515
Ad esempio:
1616

17-
- Variabili locali e parametri correnti della funzione.
18-
- Variabili o parametri di altre funzioni che fanno però parte della catena delle chiamate annidate.
17+
- Funzioni in esecuzione, i loro parametri e le loro variabi locali.
18+
- Funzioni che fanno parte della catena delle chiamate annidate, i loro parametri e le loro variabi locali.
1919
- Variabili globali.
20-
- (ce ne sono altre)
20+
- (ce ne sono altri, anche interni)
2121

2222
Questi valori sono detti *radici*.
2323

1-js/04-object-basics/04-object-methods/7-calculator/_js.view/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ describe("calculator", function() {
1515
afterEach(function() {
1616
prompt.restore();
1717
});
18+
19+
it('the read get two values and saves them as object properties', function () {
20+
assert.equal(calculator.a, 2);
21+
assert.equal(calculator.b, 3);
22+
});
1823

1924
it("the sum is 5", function() {
2025
assert.equal(calculator.sum(), 5);

1-js/04-object-basics/06-constructor-new/2-calculator-constructor/_js.view/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ describe("calculator", function() {
1010
calculator = new Calculator();
1111
calculator.read();
1212
});
13+
14+
it("the read method asks for two values using prompt and remembers them in object properties", function() {
15+
assert.equal(calculator.a, 2);
16+
assert.equal(calculator.b, 3);
17+
});
1318

1419
it("when 2 and 3 are entered, the sum is 5", function() {
1520
assert.equal(calculator.sum(), 5);

1-js/04-object-basics/06-constructor-new/article.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ La sintassi presentata in questa sessione viene utilizzata raramente, potete tra
9191

9292
Dentro la funzione, possiamo controllare quando questa viene chiamata con `new` e quando senza, utilizzando una speciale proprietà `new.target`.
9393

94-
Questa risulta vuota per le chiamate normali, mentre contiene la funzione se viene chiamata con `new`:
94+
Questa risulta 'undefined' per le chiamate normali, mentre contiene la funzione se viene chiamata con `new`:
95+
9596

9697
```js run
9798
function User() {

1-js/04-object-basics/07-optional-chaining/article.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ That's why the optional chaining `?.` was added to the language. To solve this p
7474

7575
## Optional chaining
7676

77-
The optional chaining `?.` stops the evaluation if the part before `?.` is `undefined` or `null` and returns that part.
77+
The optional chaining `?.` stops the evaluation if the value before `?.` is `undefined` or `null` and returns `undefined`.
7878

7979
**Further in this article, for brevity, we'll be saying that something "exists" if it's not `null` and not `undefined`.**
8080

8181
In other words, `value?.prop`:
82-
- is the same as `value.prop` if `value` exists,
82+
- works as `value.prop`, if `value` exists,
8383
- otherwise (when `value` is `undefined/null`) it returns `undefined`.
8484

8585
Here's the safe way to access `user.address.street` using `?.`:
@@ -103,7 +103,7 @@ alert( user?.address.street ); // undefined
103103
104104
Please note: the `?.` syntax makes optional the value before it, but not any further.
105105
106-
E.g. in `user?.address.street.name` the `?.` allows `user` to be `null/undefined`, but it's all it does. Further properties are accessed in a regular way. If we want some of them to be optional, then we'll need to replace more `.` with `?.`.
106+
E.g. in `user?.address.street.name` the `?.` allows `user` to safely be `null/undefined` (and returns `undefined` in that case), but that's only for `user`. Further properties are accessed in a regular way. If we want some of them to be optional, then we'll need to replace more `.` with `?.`.
107107
108108
```warn header="Don't overuse the optional chaining"
109109
We should use `?.` only where it's ok that something doesn't exist.
@@ -173,18 +173,16 @@ Then `?.()` checks the left part: if the admin function exists, then it runs (th
173173
The `?.[]` syntax also works, if we'd like to use brackets `[]` to access properties instead of dot `.`. Similar to previous cases, it allows to safely read a property from an object that may not exist.
174174
175175
```js run
176+
let key = "firstName";
177+
176178
let user1 = {
177179
firstName: "John"
178180
};
179181

180-
let user2 = null; // Imagine, we couldn't authorize the user
181-
182-
let key = "firstName";
182+
let user2 = null;
183183

184184
alert( user1?.[key] ); // John
185185
alert( user2?.[key] ); // undefined
186-
187-
alert( user1?.[key]?.something?.not?.existing); // undefined
188186
```
189187
190188
Also we can use `?.` with `delete`:

1-js/04-object-basics/08-symbol/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Non ci saranno conflitti, poiché i simboli saranno sempre differenti, anche se
9797

9898
Invece se proviamo ad utilizzare una stringa `"id"` piuttosto del symbol, *otterremo* un conflitto:
9999

100-
```js run
100+
```js
101101
let user = { name: "John" };
102102

103103
// il nostro script utilizza la proprietà "id"

1-js/05-data-types/02-number/article.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,30 @@ Immaginiamo di dover scrivere 1 milione. La via più ovvia è:
1616
let billion = 1000000000;
1717
```
1818

19+
Possiamo anche usare il carattere underscore `_` come separatore:
20+
21+
```js
22+
let billion = 1_000_000_000;
23+
```
24+
25+
Qui il carattere `_` gioca il ruolo di "szucchero sintattico", cioè rende il numero più leggibile. Il motore JavaScript semplicemente ignorerà i caratteri `_` tra le cifre, quindi è come scrive il milione di poco sopra.
26+
1927
Nella vita reale però cerchiamo di evitare di scrivere lunghe file di zeri per evitare errori. E anche perché siamo pigri. Solitamente scriviamo qualcosa del tipo `"1ml"` per un milione o `"7.3ml"` 7 milioni e 300mila. Lo stesso vale per i numeri più grandi.
2028

2129
In JavaScript, possiamo abbreviare un numero inserendo la lettera `"e"` con il numero di zeri a seguire:
2230

2331
```js run
2432
let billion = 1e9; // 1 miliardo, letteralmente: 1 e 9 zeri
2533

26-
alert( 7.3e9 ); // 7.3 miliardo (7,300,000,000)
34+
alert( 7.3e9 ); // 7.3 miliardi (equivale a 7300000000 o 7_300_000_000)
2735
```
2836

2937
In altre parole, `"e"` moltiplica il numero `1` seguito dal numero di zeri dati.
3038

39+
3140
```js
32-
1e3 = 1 * 1000
33-
1.23e6 = 1.23 * 1000000
41+
1e3 = 1 * 1000 // e3 means *1000
42+
1.23e6 = 1.23 * 1000000 // e6 means *1000000
3443
```
3544

3645
Ora proviamo a scrivere qualcosa di molto piccolo. Ad esempio, 1 microsecondo (un milionesimo di secondo):
@@ -125,7 +134,8 @@ Ci sono diverse funzioni integrate per eseguire questa operazione:
125134
: Arrotonda per eccesso: `3.1` diventa `4`, e `-1.1` diventa `-1`.
126135
127136
`Math.round`
128-
: Arrotonda all'intero più vicino: `3.1` diventa `3`, `3.6` diventa `4` e `-1.1` diventa `-1`.
137+
138+
: Arrotonda all'intero più vicino: `3.1` diventa `3`, `3.6` diventa `4`, e `3.5` viene arrotondato anch'esso a `4`.
129139
130140
`Math.trunc` (non supportato da Internet Explorer)
131141
: Rimuove tutto dopo la virgola decimale senza arrotondare: `3.1` diventa `3`, `-1.1` diventa `-1`.

1-js/05-data-types/10-destructuring-assignment/article.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ let [name1, name2] = ["Julius", "Caesar", "Consul", "of the Roman Republic"];
166166

167167
alert(name1); // Julius
168168
alert(name2); // Caesar
169+
169170
// Gli elementi successivi non vengono assegnati
171+
170172
```
171173

172174
Se vogliamo anche ottenere tutto ciò che segue, possiamo aggiungere un altro parametro che raccoglie "il resto" utilizzando tre punti `" ... "`:

0 commit comments

Comments
 (0)