English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM console.assert() method

 JavaScript Console Object

If assert is false ,console.assert()The method will write the error message to the console.

If assert is true, nothing will happen.

Syntax:

console.assert(assertion, 'message')
console.assert(document.getElementById("result"), 'No ID element'result'
Test and see‹/›

Browser compatibility

All browsers fully support the console.assert() method:

Method
console.assert()isisisisis

Parameter value

ParameterDescription
assertionAny boolean expression. IfassertIf false, the message is written to the console
messageString or object to be written in the console

More Examples

This example writes a string to the console:

console.assert(false, "Hello world!!!");
Test and see‹/›

This example writes an object to the console:

var myObj = { str: "Some text", id: 12 };
console.assert(document.getElementById("result"), myObj);
Test and see‹/›

This example writes an array to the console:

var arr = ["Item1", "Item2", "Item3", "Item4"];
console.assert(document.getElementById("result"), arr);
Test and see‹/›

 JavaScript Console Object