JavaScript · The language round

What is the difference between var, let and const?

EasyscopehoistingdeclarationsUpdated Oct 2026
Quiz this track

Short answer

var is function-scoped and initialised to undefined when hoisted. let and const are block-scoped and stay in the temporal dead zone until their declaration runs. const prevents reassignment, not mutation.

The interview answer has three parts: scope, hoisting and reassignment. Most candidates stop at "const means constant", which is where the follow-up lands.

Scope

js
function scopeDemo() {
  if (true) {
    var functionScoped = "var";
    let blockScoped = "let";
  }

  console.log(functionScoped); // "var"
  console.log(blockScoped); // ReferenceError
}

var belongs to the nearest function, so it escapes the if block. let and const belong to the nearest block, which makes them safer for loops and conditionals.

Hoisting and the temporal dead zone

js
console.log(a); // undefined
var a = 1;

console.log(b); // ReferenceError: Cannot access 'b' before initialization
let b = 2;

var is hoisted and initialised to undefined. let and const are also hoisted, but they are not initialised until execution reaches the declaration. The period between entering the scope and initialisation is the temporal dead zone.

Reassignment vs mutation

js
const user = { name: "Asha" };
user.name = "Ravi"; // allowed: mutating the object
user = {}; // TypeError: assignment to a constant binding

const locks the binding, not the value. Use const by default, switch to let only when the variable is reassigned, and avoid var in new code.

Common mistakes

  • Saying const makes an object immutable. Use Object.freeze() for shallow immutability when you need it.
  • Saying let and const are not hoisted. They are hoisted but remain uninitialised.
  • Using var inside a loop with callbacks, then wondering why every callback sees the final index.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Is a `const` object immutable?
  2. 2What is the temporal dead zone?
  3. 3Do `let` and `const` hoist?
  4. 4Why does `var` inside a loop behave differently from `let`?

Say it in the interview

`var` is function-scoped, hoisted and initialised to undefined. `let` and `const` are block-scoped and sit in the temporal dead zone until their declaration executes. `const` prevents reassigning the binding but does not freeze the object, so properties can still change. I default to `const`, use `let` only for reassignment, and avoid `var` in new code.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live JavaScript mock interview and get scored feedback on depth, clarity and confidence.