Re:JavaScript quiz that may confuse you
by squirtle24 on Tuesday May 03, 2022 @02:10AM
(#31245235)
I didn't notice this quirk about global vars either, and indeed if you copypaste into jsfiddle both console.logs are actually undefined.
TIL if you use strict mode, undefined vars do not become global.
[ Parent
| on HN ]
The question have error.
You need to call `foo()` before the first `console.log` to get that behavior.
function foo() {
let a = b = 0
a++
return a
}
foo() // <------ INSERT THIS
console.log(typeof a)
console.log(typeof b)