Wednesday, December 4, 2013

the better way to array

A coworker suggested to me today that...

var data = [];

 
 

...is a better way to new up an array in JavaScript than...

var data = new Array();

 
 

...as the second approach might confuse an eighty-year-old who has only done C and C++ into believing that memory is being set aside on "the stack" (which doesn't exist in JavaScript wherein everything goes on "the heap" so to speak). The first way does seem like a better convention.

No comments:

Post a Comment