HTML DOM console.assert() Method
Example
Write a message to the console, only if the first argument is false:
console.assert(document.getElementById("demo"), "You have no element with ID 'demo'");
Try it Yourself »
Definition and Usage
The console.assert() method writes a message to the console, but only if an expression evaluates to false.
Browser Support
The numbers in the table specify the first browser version that fully supports the method.
Method | |||||
---|---|---|---|---|---|
console.assert() | Yes | Yes | 28 | Yes | Yes |
Syntax
console.assert(expression, message)
Parameter Values
Parameter | Type | Description |
---|---|---|
expression | A Boolean expression | Required. The message or object to write in the console |
message | String or Object | Required. The message or object to write in the console |
More Examples
Example
Write an object to the console:
var myObj = { firstname : "John", lastname : "Doe" };
console.assert(document.getElementById("demo"), myObj;
Try it Yourself »
Example
Write an Array to the console:
var myArr = ["Orange", "Banana", "Mango", "Kiwi" ];
console.assert(document.getElementById("demo"), myArr;
Try it Yourself »