javascriptarraysboolean

Boolean Logic Regarding empty arrays.


quick question:

why does this return false? Just curious.


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


Solution

  • 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);