Pinkie Pinkie - 3 months ago 8
Javascript Question

JavaScript arrays braces vs brackets

What is the difference between each of the following array definitions.

var myArray = [];
var myArray = {};
var myArray = new Array();


The first and third are equivalent and create a new array. The second creates a new empty object, not an array.

var myArray = []; //create a new array
var myArray = {}; //creates **a new empty object**
var myArray = new Array(); //create a new array