Skip to content

Commit

Permalink
Update let.md
Browse files Browse the repository at this point in the history
  • Loading branch information
frascu authored Oct 1, 2020
1 parent 69e96d2 commit 0935b38
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions docs/let.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ if (true) {
console.log(foo); // 123
```

Another place where `let` would save you from errors is loops.
Un altro posto in cui `let` ti salverebbe dagli errori sono i cicli.

```ts
var index = 0;
var array = [1, 2, 3];
Expand All @@ -28,11 +29,10 @@ for (let index = 0; index < array.length; index++) {
}
console.log(index); // 0
```
In all sincerity we find it better to use `let` whenever possible as it leads to lesser surprises for new and existing multi-lingual developers.

#### Functions create a new scope
Since we mentioned it, we'd like to demonstrate that functions create a new variable scope in JavaScript. Consider the following:
In tutta sincerità riteniamo che sia meglio usare `let` ogni volta che è possibile, perché porta a minori sorprese per gli sviluppatori multilingue nuovi ed esistenti.

#### Funzioni che creano un nuovo scope
Visto che ne abbiamo parlato, vorremmo dimostrare che le funzioni creano un nuovo variable scope in JavaScript. Considera quanto segue:
```ts
var foo = 123;
function test() {
Expand All @@ -41,10 +41,10 @@ function test() {
test();
console.log(foo); // 123
```
This behaves as you would expect. Without this it would be very difficult to write code in JavaScript.
Questo si comporta come ci si aspetterebbe. Senza questo sarebbe molto difficile scrivere codice in JavaScript.

#### Generated JS
The JS generated by TypeScript is simple renaming of the `let` variable if a similar name already exists in the surrounding scope. E.g. the following is generated as is with a simple replacement of `var` with `let`:
#### JS generato
Il JS generato da TypeScript è una semplice ridenominazione della variabile `let` se un nome simile esiste già nello scope circostante. Ad esempio, viene generato quanto segue, così com'è con una semplice sostituzione di `var` con `let`:

```ts
if (true) {
Expand All @@ -57,7 +57,7 @@ if (true) {
var foo = 123;
}
```
However if the variable name is already taken by the surrounding scope then a new variable name is generated as shown (notice `_foo`):
Tuttavia, se il nome della variabile è già preso dallo scope circostante, allora viene generato un nuovo nome di variabile come mostrato (notare `_foo`):

```ts
var foo = '123';
Expand Down

0 comments on commit 0935b38

Please sign in to comment.