0

hello i a m learning the javascript and I am wondering whether you can help me understand why there are two ways to make a new array?

From book I see the author is using:

var myArray = new Array("one","two",3);

Also seeing on the web

var myArray = ["one","two",3];

Can someone please explain to me what is the difference?

user3152131
  • 543
  • 3
  • 7
  • 18
  • From my understanding, they are the exact same, just a preference on which one you like better. – Nate Dec 20 '15 at 02:23
  • With array literals, the VM knows we want an array; with new Array, the VM needs to use extra CPU cycles to figure out what new Array actually does. http://stackoverflow.com/a/7375418/1837472 – Data Dec 20 '15 at 02:32

0 Answers0