Open In App

What’s the difference between “Array()” and “[]” while declaring a JavaScript array?

Consider the below codes:

var myArray = new Array(5);

and



var myArray = [5];

Though these two lines might appear the same, but it is not the case.

Consider the below explanations:
Case 1: var myArray = new Array(5)



Case 2: var myArray = [5]

Article Tags :