var vs let vs const, and why you should almost never use var again.
var is function scoped and can be redeclared. It also gets hoisted, which means you can reference it before you declared it and get undefined instead of an error. That is the source of some genuinely confusing bugs.
let is block scoped. It exists only inside the braces it was declared in, and it can be reassigned.
const is block scoped and cannot be reassigned.
One detail interviewers like: const does not make an object immutable. You cannot point the name at something new, but you can still change the properties inside it. Use readonly or Object.freeze if you need more.
Practical rule: use const by default, let when the value genuinely changes, var never.
Save this ✅
#typescript #javascript #playwright #sdet #interviewpreparation #testautomation