Skip to main content

assert

method Console.assert
Jump to headingConsole.assert(
value: any,
message?: string,
...optionalParams: any[],
): void

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.

console.assert(true, 'does nothing');

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

console.assert();
// Assertion failed

Parameters Jump to heading

The value tested for being truthy.

optional
Jump to headingmessage: string

All arguments besides value are used as error message.

Jump to heading<span>...optionalParams</span>: any[]

Return Type Jump to heading

void
Back to top