Skip to main content
Console.assert - node__console.d.ts - Node documentation
method Console.assert

Usage in Deno

```typescript import { type Console } from "node:node__console.d.ts"; ```
Console.assert(
value: any,
message?: string,
...optionalParams: any[],
): void
`console.assert()` writes a message if `value` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/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()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args). If `value` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), nothing happens. ```js console.assert(true, 'does nothing'); console.assert(false, 'Whoops %s work', 'didn\'t'); // Assertion failed: Whoops didn't work console.assert(); // Assertion failed ```

Parameters

value: any
The value tested for being truthy.
optional
message: string
All arguments besides `value` are used as error message.
...optionalParams: any[]

Return Type

void