+ 2
Chrome dev tools consider variable undefined
Why is it that the chrome debugger shows undefined when I declare my javascript variables with let but not var?
1 Odpowiedź
+ 2
Did you try "use strict"? That could be the error. As of late 2019, you shouldn't have to use strict mode, but that could be the error. Another error might be that you referenced a variable created inside a block statement, but tried to reference the variable outside of a block statement, like this:
let x = 5;
if (x == 5)
{
let y = 5;
}
console.log(y); //will either return undefined or ReferenceError
The only, final error I could think of was that maybe you referenced the variable created with let before creating it. That works with the var keyword, but that doesn't work with the let keyword.