Skip to content

Commit

Permalink
doc: simplify and clarify console.assert() documentation
Browse files Browse the repository at this point in the history
PR-URL: #34544
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
Trott authored and addaleax committed Sep 22, 2020
1 parent 622fd8e commit 02bb9b7
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions doc/api/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,23 @@ changes:
* `value` {any} The value tested for being truthy.
* `...message` {any} All arguments besides `value` are used as error message.

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

If `value` is [truthy][], nothing happens.

```js
console.assert(true, 'does nothing');
// OK

console.assert(false, 'Whoops %s work', 'didn\'t');
// Assertion failed: Whoops didn't work

console.assert();
// Assertion failed
```

Calling `console.assert()` with a falsy assertion will only cause the `message`
to be printed to the console without interrupting execution of subsequent code.

### `console.clear()`
<!-- YAML
added: v8.3.0
Expand Down Expand Up @@ -560,5 +559,7 @@ This method does not display anything unless used in the inspector. The
[`util.format()`]: util.html#util_util_format_format_args
[`util.inspect()`]: util.html#util_util_inspect_object_options
[customizing `util.inspect()` colors]: util.html#util_customizing_util_inspect_colors
[falsy]: https://developer.mozilla.org/en-US/docs/Glossary/Falsy
[inspector]: debugger.html
[note on process I/O]: process.html#process_a_note_on_process_i_o
[truthy]: https://developer.mozilla.org/en-US/docs/Glossary/Truthy

0 comments on commit 02bb9b7

Please sign in to comment.