HTML DOM console.assert() method
- Previous Page assert()
- Next Page clear()
- Go to the Previous Level Window Console Object
Definition and Usage
The console.assert() method writes a message to the console, but only if the result of the expression is false.
Example
Example 1
The message is written to the console only when the first parameter is false:
console.assert(document.getElementById("demo"), "You have no element with ID 'demo'");
Example 2
Write an object to the console:
var myObj = { firstname : "Bill", lastname : "Gates" }; console.assert(document.getElementById("demo"), myObj);
Example 3
Write the array to the console:
var myArr = ["Orange", "Banana", "Mango", "Kiwi" ]; console.assert(document.getElementById("demo"), myArr);
Syntax
console.assert(expression, message)
Parameter value
Parameter | Type | Description |
---|---|---|
expression | Boolean expression | Mandatory. Any expression. If the result of the expression is false, the message is written to the console. |
message | String or Object | Required. The message or object to be written in the console. |
Browser Support
The numbers in the table indicate the first browser version that fully supports this method.
Method | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
console.assert() | Support | Support | 28 | Support | Support |
- Previous Page assert()
- Next Page clear()
- Go to the Previous Level Window Console Object