Difference between let, const, and var

Learn how variable declarations differ in scope and behavior in modern JavaScript.

beginnerFundamentalsjavascriptscopevariables
Published: 11/3/2025
Updated: 11/3/2025

Question

What’s the difference between let, const, and var?


Answer

In JavaScript:

  • var is function-scoped, hoisted, and can be re-declared.
  • let and const are block-scoped and introduced in ES6.
  • const must be initialized and cannot be reassigned.
if (true) {
  var a = 10;
  let b = 20;
  const c = 30;
}

console.log(a); // âś… 10
console.log(b); // ❌ ReferenceError
console.log(c); // ❌ ReferenceError

Hoisting Difference: var declarations are hoisted with undefined, while let and const are hoisted but remain in the temporal dead zone until initialized.

Real-World Example

Use const for constants, let for values that change, and never use var unless maintaining legacy code.

Quick Practice

Predict the output:

console.log(a);
var a = 5;

Now replace var with let. What happens?

Summary

Use const by default, let for mutable bindings, and avoid var. It’s 2025 — no excuses.

Related Videos
Watch these videos to learn more about this topic
Frequently Asked Questions

Which should I use most often?

Prefer const by default, and use let only when you need to reassign the variable.


Stay Updated

Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.