This is a case of jsLint being a bit overcautious. Most browsers will automagically define the x
, but jsLint warns of this as it's easy to get a scoping bug if you don't properly init your variables, like this:
for( var x = 0; x < verdachten.length; x++ ) {
console.log(
"De verdachte is de " +
verdachten[x].leeftijd +
"jaar oud " +
verdachten[x].naam +
", de " +
verdachten[x].wie
);
}
Problems can arise if you have an x
defined somewhere else within scope:
function doStuff() {
var x = "derp";
// things
console.log(x); //=> "derp";
for(x = 0; x < 100; x++) {
// other things
console.log(x);//=> 0..99
}
console.log(x); //=> 99
// original x variable has now changed :(
}