let and const
let is block-scoped and mutable. const is block-scoped and must be assigned at declaration. Prefer const by default.
let is block-scoped and mutable. const is block-scoped and must be assigned at declaration. Prefer const by default.
const PI = 3.14159;
let count = 0;
count += 1; // OK
// PI = 3; // TypeError
if (true) { let x = 10; } // x not accessible here
for (let i = 0; i < 3; i++) { /* i scoped to loop */ }
const prevents reassignment, not mutation — const arr = []; arr.push(1) works fine.
More in JavaScript