Skip to content

Commit a5d2265

Browse files
doc: add options parameter to util.isDeepStrictEqual
1 parent 92a1b67 commit a5d2265

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

doc/api/util.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1553,19 +1553,49 @@ inspect.defaultOptions.maxArrayLength = null;
15531553
console.log(arr); // logs the full array
15541554
```
15551555

1556-
## `util.isDeepStrictEqual(val1, val2)`
1556+
## `util.isDeepStrictEqual(val1, val2[, options])`
15571557

15581558
<!-- YAML
15591559
added: v9.0.0
1560+
changes:
1561+
- version: REPLACEME
1562+
pr-url: https://github.com/nodejs/node/pull/00000
1563+
description: Added `options` parameter to allow skipping prototype comparison.
15601564
-->
15611565

15621566
* `val1` {any}
15631567
* `val2` {any}
1568+
* `options` {Object}
1569+
* `skipPrototypeComparison` {boolean} If `true`, prototype and constructor
1570+
comparison is skipped during deep strict equality check. **Default:** `false`.
15641571
* Returns: {boolean}
15651572

15661573
Returns `true` if there is deep strict equality between `val1` and `val2`.
15671574
Otherwise, returns `false`.
15681575

1576+
By default, deep strict equality includes comparison of object prototypes and
1577+
constructors. When `options.skipPrototypeComparison` is `true`, objects with
1578+
different prototypes or constructors can still be considered equal if their
1579+
enumerable properties are deeply strictly equal.
1580+
1581+
```js
1582+
const util = require('node:util');
1583+
1584+
function Foo(a) { this.a = a; }
1585+
1586+
function Bar(a) { this.a = a; }
1587+
1588+
const foo = new Foo(1);
1589+
const bar = new Bar(1);
1590+
1591+
// Different constructors, same properties
1592+
console.log(util.isDeepStrictEqual(foo, bar));
1593+
// false
1594+
1595+
console.log(util.isDeepStrictEqual(foo, bar, { skipPrototypeComparison: true }));
1596+
// true
1597+
```
1598+
15691599
See [`assert.deepStrictEqual()`][] for more information about deep strict
15701600
equality.
15711601

0 commit comments

Comments
 (0)