0

Logic Question from Javascript

Not looking for answer, just explanation. var a={}, b={} console.log(a===b) //Returns false???? Both are same type, same scope, both empty values why are they not the same?

1st Jan 2020, 1:33 PM
Joshua Morgan
Joshua Morgan - avatar
3 Antworten
+ 2
Aren't those 2 different objects? Not sure about JavaScript but in Java it would return false because both will have different reference.
1st Jan 2020, 1:43 PM
Avinesh
Avinesh - avatar
+ 1
nice article honfu, just to provide further enrichment : the isEquivalent function in the article uses !== to check the values in the objects, this assumed that they will be string, number or boolean; when the object is nested, the values are also object-type, including array, this approach fails. instead, it should check the type of the value, and if the value is object, call isEquivalent itself.
1st Jan 2020, 2:38 PM
Gordon
Gordon - avatar