@@ -150,24 +150,23 @@ changes:
150
150
* ` value ` {any} The value tested for being truthy.
151
151
* ` ...message ` {any} All arguments besides ` value ` are used as error message.
152
152
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.
158
159
159
160
``` js
160
161
console .assert (true , ' does nothing' );
161
- // OK
162
+
162
163
console .assert (false , ' Whoops %s work' , ' didn\' t' );
163
164
// Assertion failed: Whoops didn't work
165
+
164
166
console .assert ();
165
167
// Assertion failed
166
168
```
167
169
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
-
171
170
### ` console.clear() `
172
171
<!-- YAML
173
172
added: v8.3.0
@@ -560,5 +559,7 @@ This method does not display anything unless used in the inspector. The
560
559
[ `util.format()` ] : util.html#util_util_format_format_args
561
560
[ `util.inspect()` ] : util.html#util_util_inspect_object_options
562
561
[ customizing `util.inspect()` colors ] : util.html#util_customizing_util_inspect_colors
562
+ [ falsy ] : https://developer.mozilla.org/en-US/docs/Glossary/Falsy
563
563
[ inspector ] : debugger.html
564
564
[ 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