Skip to content

Commit 3b9a252

Browse files
committed
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 3e9caaf commit 3b9a252

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
@@ -152,24 +152,23 @@ changes:
152152
* `value` {any} The value tested for being truthy.
153153
* `...message` {any} All arguments besides `value` are used as error message.
154154

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

161162
```js
162163
console.assert(true, 'does nothing');
163-
// OK
164+
164165
console.assert(false, 'Whoops %s work', 'didn\'t');
165166
// Assertion failed: Whoops didn't work
167+
166168
console.assert();
167169
// Assertion failed
168170
```
169171

170-
Calling `console.assert()` with a falsy assertion will only cause the `message`
171-
to be printed to the console without interrupting execution of subsequent code.
172-
173172
### `console.clear()`
174173
<!-- YAML
175174
added: v8.3.0
@@ -562,5 +561,7 @@ This method does not display anything unless used in the inspector. The
562561
[`util.format()`]: util.html#util_util_format_format_args
563562
[`util.inspect()`]: util.html#util_util_inspect_object_options
564563
[customizing `util.inspect()` colors]: util.html#util_customizing_util_inspect_colors
564+
[falsy]: https://developer.mozilla.org/en-US/docs/Glossary/Falsy
565565
[inspector]: debugger.html
566566
[note on process I/O]: process.html#process_a_note_on_process_i_o
567+
[truthy]: https://developer.mozilla.org/en-US/docs/Glossary/Truthy

0 commit comments

Comments
 (0)