Why new Array() is not equal to []?

Viewed 105
new Array // outputs []

[] // outputs []

But new Array === [] is false. Why so?

console.log(new Array === [])

2 Answers

Because they are two different references. They can be two arrays with no elements, but they are two completely different objects on the heap.

Because you are constructing two empty Arrays on each side of the comparison. They are not referring to the same array.

Related