closureseasy
What is the difference between var, let and const?
Answer
var is function-scoped and hoisted as undefined, so it's readable before its declaration and leaks out of blocks. let and const are block-scoped and sit in the temporal dead zone until declared, so reading them early throws. const additionally prevents reassignment of the binding — it does not freeze the value, so a const object's properties can still change.
Points an interviewer listens for
- var: function-scoped, hoisted as undefined
- let/const: block-scoped, temporal dead zone
- const blocks reassignment, not mutation
- Default to const, reach for let when you must reassign
Reported at
Similar questions have been reported by candidates at Deloitte, Neerx Technovation, Photon Technologies, TO THE NEW, Zepto, DotStark Technologies.
Now try answering it out loud
Interview practice mode times your spoken answer and checks it against the points above.
Practise this question