Are There any Differences Between Using "Array()" and "new Array()" in JavaScript?

JavaScript Array() vs. new Array()

There are no differences between calling Array() as a function or as a constructor. According to the spec, using Array(…) as a function is equivalent to using the expression new Array(…) to create an Array object instance with the same arguments. To demonstrate this, let's consider the following examples:

// output: []
console.log(Array());
console.log(new Array());
const x = Array(3);
const y = new Array(3);

// output: array of 3 empty slots
console.log(x);
console.log(y);

// output: 3
console.log(x.length);
console.log(y.length);
const x = Array(1, 2, 3);
const y = new Array(1, 2, 3);

// output: [1, 2, 3]
console.log(x);
console.log(y);

// output: 3
console.log(x.length);
console.log(y.length);

Hope you found this post useful. It was published . Please show your love and support by sharing this post.