0

quick question:

why does this return false? Just curious.


    var myArray = [];
    var myArray1 = new Array();
    console.log(myArray === myArray1)

zzgooloo
  • 75
  • 3
  • 9

2 Answers2

2

Two distinct objects are never === to one another (nor are they ==, for that matter). Object equality means that the two objects are really just one object; that is, that both sides of the === operator are references to the exact same object.

So, this will give you true:

var a = [], b = a;
console.log(a === b);
Pointy
  • 405,095
  • 59
  • 585
  • 614
  • 1
    Bro! The stuff wont work even if you do a == check, as they are separate instance. Correct me if am missing something. – Ayan Jul 16 '16 at 17:11
  • 2
    Pointy has said that _"nor are they ==, for that matter"_ – Rayon Jul 16 '16 at 17:13
0

Every time you do

  • new Array() or
  • = []

A new instance of the Array constructor is assigned to the variable. So when you do a equality check they aint same. Just as same as when two instance of a class aint same.

Ayan
  • 2,300
  • 1
  • 13
  • 28