Skip to content

Instantly share code, notes, and snippets.

@crtr0
Created December 27, 2012 18:24
Show Gist options
  • Save crtr0/4390616 to your computer and use it in GitHub Desktop.
Save crtr0/4390616 to your computer and use it in GitHub Desktop.
Can anyone explain why the if statement below never succeeds? I am running it as part of a Node.js v0.8.7 app.
var arr = ['a', 'b', 'c'];
for (i in arr) {
if (i === 0) {
console.log('do something special')
}
}
// sadly, that console.log never happens
@crtr0
Copy link
Author

crtr0 commented Dec 27, 2012

You're right, but why isn't it an integer in the first place? Why is it "0", "1" and "2" instead of 0, 1 and 2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment