Why does the following line return false in Javascript:
false
[[1,2,3], [1,2,4]].includes([1,2,3]);
What is the underlying logic behind that?
includes compares using SameValueZero equality algorithm. (As mentioned in developer.mozilla.org). When searching for objects (array is object as well), it will match only references to the same object.
includes
Additionally, Javascript arrays are objects and you can't simply use the equality operator == to understand if the content of those objects is the same. The equality operator will only test if two object are actually exactly the same instance (e.g. myObjVariable==myObjVariable, works for null and undefined too).
==
myObjVariable==myObjVariable
null
undefined
2.1m questions
2.1m answers
60 comments
57.0k users