javascript-collections-framework
    Preparing search index...

    Function equals

    • Returns whether two values are equal by value.

      Primitives compare with SameValueZero, as native Map does: NaN equals NaN, -0 equals 0, null does not equal undefined. Two objects that both implement [equalsSymbol] are compared by a[equalsSymbol](b); any other objects, and all functions and classes, by identity. Methods named equals are not used.

      Time: O(1) plus the [equalsSymbol] method when one is called.

      Parameters

      • a: unknown

        The first value.

      • b: unknown

        The second value.

      Returns boolean

      true when the values are equal.

      TypeError when [equalsSymbol] returns a value that is not a boolean.

      equals(Number.NaN, Number.NaN) // true
      equals({ x: 1 }, { x: 1 }) // false: plain objects compare by identity
      equals(new Point(1, 2), new Point(1, 2)) // true when Point implements the protocol