JavaScript var vs let vs const: Scope, Hoisting, and Reassignment

JavaScript Interview Question: var vs let vs const (Theory) Q: What is the difference between var, let, and const in JavaScript? The difference comes down to scope, hoisting, and reassignment behavior. A) var 1) Function-scoped 2) Hoisted and initialized with undefined 3) Can be redeclared and reassigned 4) Can cause bugs due to scope leakage B) let 1) Block-scoped 2) Hoisted but in the Temporal Dead Zone (TDZ) 3) Can be reassigned but not redeclared in the same scope C) const 1) Block-scoped 2) Hoisted but in TDZ 3) Cannot be reassigned 4) Object properties can still be mutated 📌 Best Practice: Use const by default, let when reassignment is needed, and avoid var in modern JavaScript. #JavaScript #WebDevelopment #FrontendDevelopment #MERNStack #InterviewPreparation #SoftwareEngineering #Developers

To view or add a comment, sign in

Explore content categories