How do let, const, and var differ in scope and reassignment?
Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Saved automatically
Model Answer & Deep-Dive Explanation
let and const are block-scoped, while var is function-scoped or script-global depending on context. const prevents reassigning the binding, but it does not make a referenced object immutable. let permits reassignment. Accessing a let or const binding before initialization throws because it is in the temporal dead zone. var declarations are initialized to undefined before their assignment executes. Prefer const when the binding will not change and let when reassignment is intentional; understanding scope matters more than treating the keywords as interchangeable style choices.
Related Questions in JavaScript & Web Technologies
Explain the JavaScript Event Loop, Call Stack, Microtask, and Macrotask Queues
Intermediate level • 425 views
What is a closure? Show a practical example.
Easy level • 2 views
What is the output of synchronous code, a resolved promise, and setTimeout with zero delay?
Medium level • 1 views
How should fetch code handle HTTP errors and malformed JSON?
Medium level • 1 views
How do event bubbling and delegation help with a dynamic list of buttons?
Medium level • 1 views