I’m sure it’s a little caveat somewhere but, here is the issue:
var x = x || {}; // Works!
let y = y || {}; // ReferenceError: can't access lexical declaration 'y' before initialization
const z = z || {}; // ReferenceError: can't access lexical declaration 'z' before initialization
The let
and const
cases throw “ReferenceError: can't access lexical declaration 'variableName' before initialization”.
What is going on here? I can kind of understand the const
one, but how is let
not working either?