Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

console.assert — diagnostic condition checks

console.assert reports a failed condition in the console without stopping execution or replacing validation.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

console.assert(condition, ...data)

console.assert(condition, ...data) belongs to the Console Standard, not a particular ECMAScript edition. The condition undergoes boolean conversion: truthy means silence, falsy reports failure. An omitted condition defaults to false.

Optional data supplies a message or additional values. If the first value in data is a string, the method adds a failure prefix to it. If the first value is not a string, the method inserts a separate failure message before it and leaves any later strings unchanged. Without data, a default message is produced. Exact wording and presentation depend on the implementation.

The method returns undefined; failure itself does not throw. Use it for diagnostics, not validation enforcement. The example deliberately reports one failure, then continues execution.

Examples

const quantity = 0;
console.assert(quantity === 0, "Expected zero");
console.assert(quantity > 0, "Expected positive quantity");
console.log("Continued");

Result

Assertion failed: Expected positive quantity
Continued

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources