Skip to content

Commit 14068f8

Browse files
Trottdanielleadams
authored andcommitted
doc: update Abstract Equality Comparison text in assert.md
* Remove link to ECMAScript specification because the term Abstract Equality Comparison is no longer used there. * Edit surprising-results material * Other minor edits PR-URL: #41375 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent c951512 commit 14068f8

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

doc/api/assert.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ more on color support in terminal environments, read the tty
104104

105105
## Legacy assertion mode
106106

107-
Legacy assertion mode uses the [Abstract Equality Comparison][] in:
107+
Legacy assertion mode uses the `==` operator in:
108108

109109
* [`assert.deepEqual()`][]
110110
* [`assert.equal()`][]
@@ -121,13 +121,11 @@ import assert from 'assert';
121121
const assert = require('assert');
122122
```
123123

124-
Whenever possible, use the [strict assertion mode][] instead. Otherwise, the
125-
[Abstract Equality Comparison][] may cause surprising results. This is
126-
especially true for [`assert.deepEqual()`][], where the comparison rules are
127-
lax:
124+
Legacy assertion mode may have surprising results, especially when using
125+
[`assert.deepEqual()`][]:
128126

129127
```cjs
130-
// WARNING: This does not throw an AssertionError!
128+
// WARNING: This does not throw an AssertionError in legacy assertion mode!
131129
assert.deepEqual(/a/gi, new Date());
132130
```
133131

@@ -471,7 +469,7 @@ changes:
471469
Legacy.
472470
- version: v14.0.0
473471
pr-url: https://github.com/nodejs/node/pull/30766
474-
description: NaN is now treated as being identical in case both sides are
472+
description: NaN is now treated as being identical if both sides are
475473
NaN.
476474
- version: v12.0.0
477475
pr-url: https://github.com/nodejs/node/pull/25008
@@ -521,8 +519,8 @@ are also recursively evaluated by the following rules.
521519

522520
### Comparison details
523521

524-
* Primitive values are compared with the [Abstract Equality Comparison][]
525-
( `==` ) with the exception of `NaN`. It is treated as being identical in case
522+
* Primitive values are compared with the `==` operator,
523+
with the exception of `NaN`. It is treated as being identical in case
526524
both sides are `NaN`.
527525
* [Type tags][Object.prototype.toString()] of objects should be the same.
528526
* Only [enumerable "own" properties][] are considered.
@@ -539,8 +537,7 @@ are also recursively evaluated by the following rules.
539537
* [`WeakMap`][] and [`WeakSet`][] comparison does not rely on their values.
540538

541539
The following example does not throw an [`AssertionError`][] because the
542-
primitives are considered equal by the [Abstract Equality Comparison][]
543-
( `==` ).
540+
primitives are compared using the `==` operator.
544541

545542
```mjs
546543
import assert from 'assert';
@@ -1138,7 +1135,7 @@ changes:
11381135
Legacy.
11391136
- version: v14.0.0
11401137
pr-url: https://github.com/nodejs/node/pull/30766
1141-
description: NaN is now treated as being identical in case both sides are
1138+
description: NaN is now treated as being identical if both sides are
11421139
NaN.
11431140
-->
11441141

@@ -1155,8 +1152,8 @@ An alias of [`assert.strictEqual()`][].
11551152
> Stability: 3 - Legacy: Use [`assert.strictEqual()`][] instead.
11561153
11571154
Tests shallow, coercive equality between the `actual` and `expected` parameters
1158-
using the [Abstract Equality Comparison][] ( `==` ). `NaN` is special handled
1159-
and treated as being identical in case both sides are `NaN`.
1155+
using the `==` operator. `NaN` is specially handled
1156+
and treated as being identical if both sides are `NaN`.
11601157

11611158
```mjs
11621159
import assert from 'assert';
@@ -1471,7 +1468,7 @@ changes:
14711468
Legacy.
14721469
- version: v14.0.0
14731470
pr-url: https://github.com/nodejs/node/pull/30766
1474-
description: NaN is now treated as being identical in case both sides are
1471+
description: NaN is now treated as being identical if both sides are
14751472
NaN.
14761473
- version: v9.0.0
14771474
pr-url: https://github.com/nodejs/node/pull/15001
@@ -1653,7 +1650,7 @@ changes:
16531650
Legacy.
16541651
- version: v14.0.0
16551652
pr-url: https://github.com/nodejs/node/pull/30766
1656-
description: NaN is now treated as being identical in case both sides are
1653+
description: NaN is now treated as being identical if both sides are
16571654
NaN.
16581655
-->
16591656

@@ -1669,8 +1666,8 @@ An alias of [`assert.notStrictEqual()`][].
16691666

16701667
> Stability: 3 - Legacy: Use [`assert.notStrictEqual()`][] instead.
16711668
1672-
Tests shallow, coercive inequality with the [Abstract Equality Comparison][]
1673-
(`!=` ). `NaN` is special handled and treated as being identical in case both
1669+
Tests shallow, coercive inequality with the
1670+
`!=` operator. `NaN` is specially handled and treated as being identical if
16741671
sides are `NaN`.
16751672

16761673
```mjs
@@ -2430,7 +2427,6 @@ assert.throws(throwingFirst, /Second$/);
24302427
Due to the confusing error-prone notation, avoid a string as the second
24312428
argument.
24322429

2433-
[Abstract Equality Comparison]: https://tc39.github.io/ecma262/#sec-abstract-equality-comparison
24342430
[Object wrappers]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive#Primitive_wrapper_objects_in_JavaScript
24352431
[Object.prototype.toString()]: https://tc39.github.io/ecma262/#sec-object.prototype.tostring
24362432
[SameValue Comparison]: https://tc39.github.io/ecma262/#sec-samevalue
@@ -2466,4 +2462,3 @@ argument.
24662462
[`tracker.verify()`]: #trackerverify
24672463
[enumerable "own" properties]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties
24682464
[prototype-spec]: https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots
2469-
[strict assertion mode]: #strict-assertion-mode

0 commit comments

Comments
 (0)