var vs let vs const | Programming Interview | Skill-Lync Resources
Easy Programming & OOP JavaScript & TypeScript

What is the difference between var, let, and const in JavaScript?

Answer

var is function-scoped, hoisted with undefined initialization, can be redeclared and reassigned. let is block-scoped, hoisted but not initialized (temporal dead zone), cannot be redeclared, can be reassigned. const is block-scoped, must be initialized at declaration, cannot be reassigned (but object properties can change). Best practices: use const by default, let when reassignment needed, avoid var. let and const were introduced in ES6 to fix var's scoping issues and provide clearer intent.

Master These Concepts with IIT Certification
IIT Certified

Master These Concepts with IIT Certification

175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.

Relevant for Roles

Frontend Developer Full Stack Developer JavaScript Developer