Docly Developers
Function Updated 17 Oct 2026

console.assert(condition, message)

Throws an error with the given message when a condition is false.

Parameters

conditionboolrequired

The condition to test. If it evaluates to false, the assertion fails.

messagestringrequired

The error message to throw if the condition is false. Must be a string.

Returns

null when the condition is true. When it is false, throws an error with message as its text — nothing is written to the console log.

Exactly two arguments are required; any other number throws.

Example

Normal JavaScript, running in the browser or on the Docly™ server.
// Testing addition and multiplication
let result = 2 + 3 * 4;
console.assert(result === 14, `Expected 14, but got ${result}`);