When I use a for in statement, js2 mode doesn't recognize the new variable:

let foo = {bar: 1};

for(key in foo) {

It prints: Undeclared variable or function 'key'

1 Answer 1


It 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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.