JSHint considers a for-in variable 'bad'. What does this mean?

for-loop, javascript, jshint, syntax

Solution

They always are - if they are not declared. Try adding `var` if `thing` has not been previously declared.

for ( var thing in things ) {
  console.log(thing)
}

or

var thing;

//more code

for ( thing in things ) {
  console.log(thing)
}

Problem

The following code: ``` var things = {'foo':'bar'} for ( thing in things ) { console.log(thing) } ``` Consistently produces the following error in jshint: ``` Bad for in variable 'thing'. ``` I do not understand what makes the 'thing' variable 'bad' - as you can see, it is not being used anywhere else. What should I do differently to make jshint not consider this to be an error?

Original source