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() Methodh1 {
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:
Check out the console view to press F12:
Example 2: Displaying objects when using the console.assert() method
DOM console.assert() Methodh1 {
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);
output:
See the console view of pressing F12:
Supported browsers: The browsers supported by the console.assert() method are as follows:
Google Chrome
Internet Explorer
Firefox 28.0
Opera
safari