assert tag html, HTML DOM console.assert() usage and code example

The console.assert() method in HTML is only used to write a message to the user on the console if the expression evaluates to false. Expressions and messages are sent as parameters to the console.assert() method.

usage:

console.assert( expression, message )

Parameters: The method accepts two parameters as described above and below:

expression: It is a boolean expression representing the message or object to be written to the console. It is a required parameter.

message: It is a string or object representing the message or object to be written to the console. It is a required parameter.

The following sample program is intended to illustrate the console.assert() method in HTML:

Example 1:

DOM console.assert() Method

h1 {

color:green;

}

h2 {

font-family:Impact;

}

body {

text-align:center;

}

GeeksforGeeks

DOM console.assert() Method

To view the message in the console press the F12

key on your keyboard.

console.assert(document.getElementById("MyElement"),

"There is no element with the ID 'MyElement'");

output:

5b1e3c75830e87d9cb9eef375d0e6842.png

Check out the console view to press F12:

8907dbfb2080beef5acb320b79282c60.png

Example 2: Displaying objects when using the console.assert() method

DOM console.assert() Method

h1 {

color:green;

}

h2 {

font-family:Impact;

}

body {

text-align:center;

}

GeeksforGeeks

DOM console.assert( ) Method

To view the message in the console press the F12 key on

your keyboard.

var MyElement = { Product:"Coca Cola", Type:"Beverage" };

console.assert(document.getElementById("MyDemo"), MyElement);

输出:

5b1e3c75830e87d9cb9eef375d0e6842.png

请参阅按F12键的控制台视图:

28287ad8584c70d139f1edc5f5528c1d.png

支持的浏览器:console.assert()方法支持的浏览器如下:

谷歌浏览器

IE浏览器

Firefox 28.0

Opera

苹果浏览器

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324082220&siteId=291194637