I'm currently reading the book Secrets of the Javascript Ninja and I do not understand the following behaviour based on an example from chapter 5 explaining how function identifiers are overwritten:
code example from the book:
console.log(typeof fun);
var fun = 3;
console.log(typeof fun);
function fun() {}
console.log(typeof fun);
Output as expected: function / number / number
console.log(typeof fun);
let fun = 3;
console.log(typeof fun);
function fun() {}
console.log(typeof fun);
But when I change the definition to let I get the error that fun has already been decleared. When the lexical environment is created why can I override var but let already blocks the definition of the function declaration?
The attached question, was also answered with "let variables are not initialized until their definition is evaluated."
What's the difference between using "let" and "var"?