๐Ÿ“ฆ JavaScript

var vs let vs const in JavaScript โ€” Which and When

๐Ÿ“… Jun 11, 2026 โฑ 4 min read

Three keywords, one decision rule: const by default, let when you must reassign, var never. Here is why.

The differences

The classic trap

for (var i = 0; i < 3; i++) {
  setTimeout(() => console.log(i));  // 3, 3, 3  ๐Ÿ˜ฑ
}
for (let i = 0; i < 3; i++) {
  setTimeout(() => console.log(i));  // 0, 1, 2  โœ… new binding per loop
}

const nuance interviewers probe

const arr = [1, 2];
arr.push(3);      // โœ… fine โ€” contents can change
arr = [9];        // โŒ TypeError โ€” the BINDING is constant

const prevents reassignment, not mutation. Freeze contents with Object.freeze(). Full lesson: Variables.

โ† All Articles