-
-
Notifications
You must be signed in to change notification settings - Fork 0
equal()
Eugene Lazutkin edited this page Jul 13, 2026
·
5 revisions
This function compares two JavaScript objects for deep equivalency. It can handle objects with circular dependencies.
import equal from 'deep6';
// or: import {equal} from 'deep6';
equal({a: [1]}, {a: [1]}); // true
equal({a: [1]}, {a: [2]}); // false
equal({a: [1]}, {b: [1]}); // falseArguments:
-
a— a required argument. It can be anything. -
b— a required argument. It can be anything. -
options— an optional object. The following optional properties are recognized:-
circular— cycle handling. Whentrue, the cheapest cycle-safe algorithm is used (currently'bisimulation'); the named modes'bisimulation'|'closure'|'graph'select exact semantics — see unify() for the full description.- It is totally safe to turn it on for all objects, but checks will require more memory and more CPU. In some cases, for performance reasons, you may want to turn it off.
-
symbols— a boolean flag. Whentrue, symbol properties would be checked for equivalency as well.- Normally symbol properties are hidden from enumerating using classical means.
-
ignoreFunctions— a boolean flag. Whentrue, if both properties are functions, they are assumed to be equivalent automatically. -
loose— a boolean flag. Whentrue, primitives are compared with==rather than===. -
signedZero— a boolean flag. Whentrue,+0and-0are treated as different values. - Any other properties documented in unify().
The default:
{circular: true}. -
The function returns a boolean value, which indicates the equivalence of its first two arguments.
Implemented using unify():
const defaultOptions = {circular: true};
const equal = (a, b, options = defaultOptions) => !!unify(a, b, null, options);Core functions
Environments and variables
Unification
Traverse
Unifiers
Utilities