News for hackers. Stuff that matters.
Re:A Reintroduction to JavaScript by babuskov on Monday February 03, 2014 @07:15AM (#7170217)
Since I started using JS heavily lately, it's nice to be reminded of some things. Thanks for posting.

One question though, it says:

    If you want to append an item to an array, the safest way to do it is like this:
    a[a.length] = item;  // same as a.push(item);
a.push() variant seems more elegant to me. Why is a[] variant "safer"?
Re:A Reintroduction to JavaScript by bpierre on Monday February 03, 2014 @07:39AM (#7170311)
It must be for the compatibility, Array.prototype.push() has been added to IE 5.5:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re:A Reintroduction to JavaScript by cstuder on Monday February 03, 2014 @07:43AM (#7170321)
Thirteen years ago... I would argue that you could use a.push() safely now.

So, why should a[a.length] be safer?

Re:A Reintroduction to JavaScript by coldtea on Monday February 03, 2014 @10:52AM (#7171230)
He said it already, JUST for the compatibility. No other reason compared to push nowadays.
Re:A Reintroduction to JavaScript by unstabilo on Monday February 03, 2014 @08:22AM (#7170460)
Both methods are equally safe, what the author meant is that both are safer than a[14] = item or a[myCounter] = item.