News for hackers. Stuff that matters.
Re:A re-introduction to JavaScript by jckarter on Saturday July 17, 2010 @04:26PM (#1524575)
An introduction really shouldn't encourage things like "for (var i = 0, item; item = a[i]; i++)". Someone's going to cut-and-paste that because it looks cute, and their code will break when their array suddenly needs to contain null values. Fuzzy boolean semantics are bad enough without spreading stuff like this around (speaking from experience with || abuse in Perl).
Re:A re-introduction to JavaScript by freakwit on Saturday July 17, 2010 @04:44PM (#1524604)
To be fair, they do note this shortcoming.

"Note that this trick should only be used for arrays which you know do not contain "falsy" values (arrays of objects or DOM nodes for example). If you are iterating over numeric data that might include a 0 or string data that might include the empty string you should use the i, j idiom instead."

Re:A re-introduction to JavaScript by WilliamLP on Saturday July 17, 2010 @06:43PM (#1524813)
So it should be used approximately never in real code.
Re:A re-introduction to JavaScript by jackmoore on Sunday July 18, 2010 @04:45PM (#1526679)
I also think it should discourage modifying built-in objects. Unlike their for loop, the following line comes with no warning or disclaimer: "Interestingly, you can also add things to the prototype of built-in JavaScript objects."
Re:A re-introduction to JavaScript by jackmoore on Sunday July 18, 2010 @03:13PM (#1526476)
Agreed. But what is the point of declaring the item variable? Wouldn't "for (var i = 0; a[i]; i++)" mean the same thing, but more concise?