0

I'm researching object equality test functions and ran across this code in Lodash's "isEqual" function:

https://bit.dev/lodash/lodash/internal/_base-is-equal/~code

function baseIsEqual(value, other, bitmask, customizer, stack) {
  if (value === other) {
    return true;
  }
  if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
    return value !== value && other !== other;
  }
  return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
}

TLDR: When would return value !== value && other !== other; ever return true?

The part that stumps me is the 2nd conditional and its return. Clearly the 1st condition catches simple strict equality cases. But, looking at the next test, I make the following observations (assumptions?):

  • value == null is true only for 'null' and 'undefined'
  • the "isObjectLike" clause eliminates anything not a primitive or a function

So, if the only values for value and other are primitives, undefined, null or functions, what values could satisfy the condition for a true return? Seeing this code in Lodash lends it credibility, so I'm also "assuming" it is legit ("assumptions"! ... yes, I know ... ).

gkl
  • 199
  • 2
  • 11

0 Answers0