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
1.4m articles
1.4m replys
5 comments
57.0k users