feat(curriculum): introduce let and const earlier (#43133)

* fix: move "Explore Differences Between..." to basic JS, update seed and tests

* fix: resequence "Declare String Variables"

* fix: move "Declare a Read-Only Variable..." to basic JS, update seed and tests

* fix: revert changes to non-English "Explore Differences Between..." test text

* fix: revert test strings, solutions, and seeds for non-English challenges

* fix: update "Declare String Variables" description

* fix: sync quotation marks in description and seed

* fix: modify note in "Declare a Read-Only..." challenge

* fix: update operator and compound assignment challenges

* fix: update string challenges

* fix: update array and array method challenges

* fix: update function and scope challenges, resequence slightly

* fix: "Word Blanks" solution

* fix: add spacing to seed

* fix: concatenating += challenge spacing

* fix: appending variables to strings spacing

* fix: find the length of a string spacing

* fix: removed instances of removedFromMyArray = 0

* fix: switch challenges

* fix: function argument and param spacing

* fix: update counting cards, object challenges, and record collection

* fix: finish rest of Basic JS section

* fix: introducing else statements solution

* fix: update spacing and wording

* fix: update wording for const challenge

* fix: update functional programming challenges

* fix: intermediate algorithms and cert challenges

* fix: revert some spacing and remove comments for fp challenge solutions

* feat: add notes with links to moved let and const challenges in first two es6 challenges

* fix: update es6 intro text

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/global-scope-and-functions.md

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/declare-a-read-only-variable-with-the-const-keyword.md

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* fix: concatenating strings with plus operator seed

* fix: add comments back to Declare a Read-Only Variable... seed

* feat: add es6 to basic javascript redirect tests for let and const challenges

* fix: revert "Concatenating Strings with Plus Operator" seed

* fix: move test file to cypress/integration/learn/redirects, separate redirect tests

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
This commit is contained in:
Kristofer Koishigawa
2021-10-26 01:55:58 +09:00
committed by GitHub
parent 71b555ab16
commit bcc9beff1f
134 changed files with 888 additions and 882 deletions

View File

@ -0,0 +1,89 @@
---
id: 587d7b87367417b2b2512b41
title: Dichiarare una variabile di sola lettura con la parola chiave const
challengeType: 1
forumTopicId: 301201
dashedName: declare-a-read-only-variable-with-the-const-keyword
---
# --description--
La parola chiave `let` non è l'unico nuovo modo per dichiarare le variabili. In ES6, puoi anche dichiarare variabili usando la parola chiave `const`.
`const` ha tutte le fantastiche caratteristiche che ha `let`, con il il valore aggiunto che le variabili dichiarate utilizzando `const` sono di sola lettura. Esse sono un valore costante, il che significa che una volta assegnata una variabile con `const`, non può più essere riassegnata.
```js
const FAV_PET = "Cats";
FAV_PET = "Dogs";
```
La console mostrerà un errore a causa della riassegnazione del valore di `FAV_PET`.
Come puoi vedere, cercare di riassegnare una variabile dichiarata con `const` genererà un errore. Dovresti sempre dichiarare le variabili che non vuoi riassegnare usando la parola chiave `const`. Questo aiuta quando nel caso dovessi tentare accidentalmente di riassegnare il valore a una variabile che è destinata a rimanere costante. Una pratica comune quando si dà il nome alle costanti è usare tutte le lettere maiuscole, separando le parole con un underscore.
**Nota:** È pratica comune per gli sviluppatori usare identificatori di variabili a lettere maiuscole per valori immutabili e a lettere minuscole o camelCase per valori mutabili (oggetti e array). In una sfida successiva vedrai un esempio di identificatore di variabile con lettere minuscole utilizzato per un array.
# --instructions--
Modifica il codice in modo che tutte le variabili siano dichiarate utilizzando `let` o `const`. Usa `let` quando vuoi che la variabile possa cambiare e `const` quando vuoi che la variabile rimanga costante. Inoltre, rinomina le variabili dichiarate con `const` per conformarti alle pratiche comuni, il che significa che le costanti dovrebbero essere tutte in maiuscolo.
# --hints--
`var` non dovrebbe esistere nel tuo codice.
```js
(getUserInput) => assert(!getUserInput('index').match(/var/g));
```
`SENTENCE` dovrebbe essere una variabile costante dichiarata con `const`.
```js
(getUserInput) => assert(getUserInput('index').match(/(const SENTENCE)/g));
```
`i` dovrebbe essere dichiarata con `let`.
```js
(getUserInput) => assert(getUserInput('index').match(/(let i)/g));
```
`console.log` dovrebbe essere cambiato per stampare la variabile `SENTENCE`.
```js
(getUserInput) =>
assert(getUserInput('index').match(/console\.log\(\s*SENTENCE\s*\)\s*;?/g));
```
# --seed--
## --seed-contents--
```js
function printManyTimes(str) {
// Only change code below this line
var sentence = str + " is cool!";
for (var i = 0; i < str.length; i+=2) {
console.log(sentence);
}
// Only change code above this line
}
printManyTimes("freeCodeCamp");
```
# --solutions--
```js
function printManyTimes(str) {
const SENTENCE = str + " is cool!";
for (let i = 0; i < str.length; i+=2) {
console.log(SENTENCE);
}
}
printManyTimes("freeCodeCamp");
```

View File

@ -0,0 +1,91 @@
---
id: 587d7b87367417b2b2512b3f
title: Esplorare le differenze tra le parole chiave var e let
challengeType: 1
forumTopicId: 301202
dashedName: explore-differences-between-the-var-and-let-keywords
---
# --description--
Uno dei maggiori problemi quando si dichiarano delle variabili con la parola chiave `var` è che è possibile sovrascrivere le dichiarazioni delle variabili senza errori.
```js
var camper = 'James';
var camper = 'David';
console.log(camper);
```
Qui la console mostrerà la stringa `David`.
Come puoi vedere nel codice qui sopra, la variabile `camper` è originariamente dichiarata come `James` per poi essere sovrascritta con `David`. In una piccola applicazione si potrebbe non incorrere in questo tipo di problema, ma quando il codice diventa più grande, potresti accidentalmente sovrascrivere una variabile che non hai intenzione di sovrascrivere. Poiché questo comportamento non lancia un errore, la ricerca e la correzione di bug diventa più difficile.
Una nuova parola chiave, chiamata `let`, è stata introdotta in ES6 per risolvere questo potenziale problema con la parola chiave `var`. Se dovessi sostituire `var` con `let` nelle dichiarazioni delle variabili nel codice sopra, il risultato sarebbe un errore.
```js
let camper = 'James';
let camper = 'David';
```
Questo errore può essere visto nella console del tuo browser. Quindi, a differenza di `var`, quando si utilizza `let`, una variabile con lo stesso nome può essere dichiarata solo una volta. Nota l'`"use strict"`. Questo abilita la Strict Mode (Modalità Rigorosa), che cattura gli errori di codifica comuni e le azioni "non sicure". Per esempio:
```js
"use strict";
x = 3.14;
```
Questo mostrerà l'errore `x is not defined`.
# --instructions--
Aggiorna il codice in modo che utilizzi solo la parola chiave `let`.
# --hints--
`var` non dovrebbe esistere nel codice.
```js
(getUserInput) => assert(!getUserInput('index').match(/var/g));
```
`catName` dovrebbe essere uguale alla stringa `Oliver`.
```js
assert(catName === 'Oliver');
```
`quote` dovrebbe essere uguale alla stringa `Oliver says Meow!`
```js
assert(quote === 'Oliver says Meow!');
```
# --seed--
## --seed-contents--
```js
var catName;
var quote;
function catTalk() {
"use strict";
catName = "Oliver";
quote = catName + " says Meow!";
}
catTalk();
```
# --solutions--
```js
let catName;
let quote;
function catTalk() {
'use strict';
catName = 'Oliver';
quote = catName + ' says Meow!';
}
catTalk();
```