ForgeFrontend — Prepare, Practice, Crack
Secure checkout
Lifetime access
Instant Drive delivery
Free updates forever

Prepare · Practice · Crack

var vs let vs const in JavaScript

This is the most common JavaScript warm-up question. The differences come down to scope, hoisting, and reassignment — here they are, clearly.

Scope & hoisting

var is function-scoped and hoisted as undefined, so it's readable (as undefined) before its line. let and const are block-scoped and live in the Temporal Dead Zone until declared — accessing them early throws a ReferenceError.

console.log(a); // undefined (var hoisted)
var a = 1;
console.log(b); // ReferenceError (TDZ)
let b = 2;

Reassignment

const can't be reassigned — but it locks the binding, not the value. A const object's properties can still be mutated; you just can't point the variable at something new.

Get all 80+ JavaScript interview questions

Scope, closures, the event loop and every common JS question — with structured answers in the JavaScript Interview Kit.

⚡ Get the JavaScript Interview Kit → ₹299

Frequently asked questions

Does const make an object immutable?
No. const prevents reassigning the variable, but the object's contents are still mutable. Use Object.freeze for shallow immutability.
Which should I use?
const by default, let only when you must reassign, and never var in new code.

Full kit

JavaScript Interview Kit · ₹299

Get it →