Skip to content

Commit f393ae9

Browse files
Trottcodebytere
authored andcommitted
doc: simplify and clarify console.assert() documentation
PR-URL: #34544 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent b69ff2f commit f393ae9

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

doc/api/console.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,23 @@ changes:
150150
* `value` {any} The value tested for being truthy.
151151
* `...message` {any} All arguments besides `value` are used as error message.
152152

153-
A simple assertion test that verifies whether `value` is truthy. If it is not,
154-
or `value` is not passed,
155-
`Assertion failed` is logged. If provided, the error `message` is formatted
156-
using [`util.format()`][] by passing along all message arguments. The output is
157-
used as the error message.
153+
`console.assert()` writes a message if `value` is [falsy][] or omitted. It only
154+
writes a message and does not otherwise affect execution. The output always
155+
starts with `"Assertion failed"`. If provided, `message` is formatted using
156+
[`util.format()`][].
157+
158+
If `value` is [truthy][], nothing happens.
158159

159160
```js
160161
console.assert(true, 'does nothing');
161-
// OK
162+
162163
console.assert(false, 'Whoops %s work', 'didn\'t');
163164
// Assertion failed: Whoops didn't work
165+
164166
console.assert();
165167
// Assertion failed
166168
```
167169

168-
Calling `console.assert()` with a falsy assertion will only cause the `message`
169-
to be printed to the console without interrupting execution of subsequent code.
170-
171170
### `console.clear()`
172171
<!-- YAML
173172
added: v8.3.0
@@ -560,5 +559,7 @@ This method does not display anything unless used in the inspector. The
560559
[`util.format()`]: util.html#util_util_format_format_args
561560
[`util.inspect()`]: util.html#util_util_inspect_object_options
562561
[customizing `util.inspect()` colors]: util.html#util_customizing_util_inspect_colors
562+
[falsy]: https://developer.mozilla.org/en-US/docs/Glossary/Falsy
563563
[inspector]: debugger.html
564564
[note on process I/O]: process.html#process_a_note_on_process_i_o
565+
[truthy]: https://developer.mozilla.org/en-US/docs/Glossary/Truthy

0 commit comments

Comments
 (0)