by skybrian · 8y ago · 0 comments
For a string key, the hashcode field is probably a cached hash of the value, since that's how an equality comparison works. Most objects are only equal to themselves, are mutable, and get moved in memory, so storing a unique identifier is the only way to know if it's the same object that you saw before.
For a hash code, the identifier doesn't need to be unique since all that matters is that it's consistently placed in the same bucket. All you need is to store a sufficiently long random number.
[1] SameValueZero equality as defined at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equa...