When I use a for in statement, js2 mode doesn't recognize the new variable:
let foo = {bar: 1};
for(key in foo) {
console.log(key);
}
It prints: Undeclared variable or function 'key'
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityIt warns you that the key
variable is undeclared, and using it like this, you leak it into the global namespace.
Try this is your browser console:
> let foo = {bar: 1};
> for(key in foo) {}
> key
=> "bar"