Object.is
The JavaScript function that tells whether two values are the same value, comparing objects by identity.
In more detail
For objects and arrays it checks identity, not contents: two separate objects with equal fields are different. It differs from === only for NaN, which it treats as equal to itself, and for +0 and -0, which it treats as different.
Example
React uses Object.is to decide whether state, props, context values or dependencies changed.Related terms
- reference equality — Comparing two references to see whether they point to the very same object, rather than to objects with equal contents.
- shallow comparison — Comparing two objects one property at a time with Object.is, without looking inside nested objects.
Taught in
- State with useState: Immutability And Asynchronous Batching — React 19 & Modern Component Architecture
- useContext in Depth: Scoping, Consumer Subscription Costs — React 19 & Modern Component Architecture
- React.memo, useMemo, And useCallback: Optimization Costs — React 19 & Modern Component Architecture
- The React Compiler: Automated Memoization Under The Hood — React 19 & Modern Component Architecture