I have recently noticed below code works
var x = 10;
var x = 20;
on the other side below throws error for redeclaration of same variable
let x = 10;
let x = 20;
Below link gives insights by keeping functional scope
vs block scope
as reference.
Why does var allow duplicate declaration but why does const and let not allow duplicate declaration?
var
declarations are executed in execution context
, a entry in variableObject is created and re-declarations points to same entry/variable again and again in case of duplication.
How is this different in case of let
?
Isn't it still executed in execution context
?
Some good links or detailed explanation would be appreciated.