HTML DOM console.assert()Method

Console 对象Console Object

Examples

If the first parameter is false, output information in the console:

console.assert(document.getElementById("demo"), "No element with ID 'demo'");

Try it Yourself »

Definition and Usage

The console.assert() method outputs information to the console if the first parameter is false.


Syntax

console.assert(expression, message)

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

Parameter Description

Parameter Type Description
Expression Boolean expression Required. A boolean expression that returns true or false.
Message String or Object Required. The message or object to write to the console.

More Examples

Example

Write an object to the console:

var myObj = { name : "Example", site : "www.example.com" }; console.assert(document.getElementById("demo"), myObj);

Try it Yourself »

Example

Write an array to the console:

var myArr = ["Google", "Taobao", "Example", "Facebook" ]; console.assert(document.getElementById("demo"), myArr);

Try it Yourself »

Console 对象Console Object

Other Extensions