Consider the following code:
const testArray = ['string1', 'string2', 'string3'];
for (let iterator in testArray) {
console.log(iterator == 0);
}
My IDE (Visual Studio Code), complains about the console.log
, that it will always return false (error: ts(2367)
)
But if I input this code directly either here, or in a JSBin, or in my current browser, I always get the true
result on the first iteration. Anyone can explain me, if my IDE is to blame for this, or maybe there is some legacy javascript, where that condition indeed always returns false?
Based on this table https://dorey.github.io/JavaScript-Equality-Table/ it also seems that the above code is valid, and will run as expected.
const testArray = ['string1', 'string2', 'string3'];
for (let iterator in testArray) {
console.log(iterator == 0);
}