Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 261fd11

Browse filesBrowse files
Trottaddaleax
authored andcommitted
doc: simplify and clarify console.assert() documentation
PR-URL: #34544 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent b4b2057 commit 261fd11
Copy full SHA for 261fd11

File tree

Expand file treeCollapse file tree

1 file changed

+10
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-9
lines changed
Open diff view settings
Collapse file

‎doc/api/console.md‎

Copy file name to clipboardExpand all lines: doc/api/console.md
+10-9Lines changed: 10 additions & 9 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.