Chapter 210m

let & const

Declare variables the modern way.

This content is not yet available in si. Showing English version.

View in English →

let & const

Use let for variables that change, const for values that don't.

js
let score = 0;
score = 10;  // OK

const pi = 3.14;
pi = 3;      // ❌ TypeError

Old var

Avoid var — it has function scope and is hoisted, which causes bugs. Always prefer let / const.

Example

javascript
// let and const
let score = 0;
score = 10;
console.log("Score:", score);

const playerName = "Aarav";
console.log("Player:", playerName);