Thuta Learning
BasicProgrammingbeginner

JS Variables (var, let, const)

Relax. We'll talk through this in plain words — no textbook voice.

JavaScript has three keywords for declaring variables.

var: (the old way) function-scoped, and best avoided these days.

let: block-scoped ({}) whose value can be reassigned. It can't be re-declared.

const: block-scoped, and its value cannot be reassigned (constant). You must assign it a value when you declare it.

As a general rule, use const for values that don't need to change, and let when you do need to change them.

javascript
let name = "Alice"; // Can be changed
name = "Bob";
console.log(name);

const birthYear = 2000; // Cannot be changed
// birthYear = 2001; // This will cause a TypeError

var city = "Yangon"; // Old way
console.log(city);
You should see
Bob Yangon
JS Variables (var, let, const) | Thuta Learning