News for hackers. Stuff that matters.
Re:A Reintroduction to JavaScript by Drakim on Monday February 03, 2014 @04:00PM (#7173448)
Unless I'm mistaken, wouldn't this loop terminate prematurely if the array contains any falsy value, such as undefined, null, false, NaN, or 0?
Re:A Reintroduction to JavaScript by joebadmo on Monday February 03, 2014 @04:05PM (#7173478)
Yes, there's a note right after:

    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, len 
    idiom instead.
Re:A Reintroduction to JavaScript by Wintamute on Monday February 03, 2014 @05:17PM (#7173915)
You're correct. Seems like a pretty useless/dangerous idiom to me. How often can you be sure that in 100% of cases your loop will never iterate a 0, an empty string or some other falsey value?