Q2: What is the difference between var, let, and const?
var is function-scoped (or globally scoped) and hoisted with an initial value of undefined. let and const are block-scoped and hoisted into a Temporal Dead Zone (TDZ). const creates a read-only variable reference that cannot be reassigned after declaration.
Key Takeaways
varis function-scoped;letandconstare block-scoped.letandconstexist in the Temporal Dead Zone prior to declaration.
Knowledge Check
What error occurs when accessing a let variable before its declaration line?