FCC - ES6 LET & CONST
by vanduzled
JavaScript
//So unlike var, when using let, a variable with the same name can only be declared once.
let catName;
let quote;
function catTalk() {
"use strict";
catName = "Oliver";
quote = catName + " says Meow!";
}
catTalk();
// Declare a Read-Only Variable with the const Keyword
//once a variable is assigned with const, it cannot be reassigned.
function printManyTimes(str) {
// Only change code below this line
const SENTENCE = str + " is cool!";
for (let i = 0; i < str.length; i+=2) {
console.log(SENTENCE);
}
// Only change code above this line
}
printManyTimes("freeCodeCamp");
//Mutate an Array Declared with const
//You can change the content of an array but you cannot assign it anymore to other arrays
const s = [5, 7, 2];
function editInPlace() {
// Only change code below this line
s[0] = 2;
s[1] = 5;
s[2] = 7;
// Using s = [2, 5, 7] would be invalid
// Only change code above this line
}
editInPlace();
//Change the array to [2, 5, 7] using various element assignments.