javascript-collections-framework
    Preparing search index...

    Function hashCode

    • Returns a hash of value that agrees with equals: equal values have equal hashes.

      An object implementing both [equalsSymbol] and [hashCodeSymbol] is hashed by value[hashCodeSymbol](hashCode), reduced to a 32-bit integer. Primitives are hashed by value (with NaN alike and -0 as 0) without calling any user code; other objects, functions and classes by identity (for an object, only its two protocol keys are read, which can run a getter or a Proxy trap). Hash values are seeded: they differ between runs and between loaded copies of the library, so never store or send them.

      Time: O(1) for numbers, booleans, null and undefined; O(1) amortised for objects; O(length) for strings and symbol descriptions; O(digits) for bigints; plus the [hashCodeSymbol] method when one is called.

      Parameters

      • value: unknown

        Any value.

      Returns number

      A 32-bit integer.

      TypeError when [hashCodeSymbol] returns a value that is not a finite number, or the object implements only one of [equalsSymbol] and [hashCodeSymbol].

      hashCode(Number.NaN) === hashCode(0 / 0) // true
      hashCode(-0) === hashCode(0) // true