Lesson 2 of 55 · javascript
Variables – var, let & const
Duration: 9 mins
Three ways to declare variables:
| Keyword | Scope | Re‑assignment | Hoisting |
|---|---|---|---|
var | Function‑scoped | ✅ | Yes (initialised as undefined) |
let | Block‑scoped | ✅ | No (Temporal Dead Zone) |
const | Block‑scoped | ❌ (immutable binding) | No (TDZ) |
Example:
var a = 1; // function‑scoped, can be redeclared
let b = 2; // block‑scoped, cannot be redeclared in the same block
const C = 3; // block‑scoped, constant binding