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'");
<!DOCTYPE html> <html> <body> <script> console.assert(document.getElementById("demo"), "You have no element with ID 'demo'"); </script>/*from ww w . ja v a2 s . c o m*/ </body> </html>
The console.assert()
method writes a message to the console, only if an expression evaluates to false.
console.assert(expression, message);
Parameter Values
Parameter | Type | Description |
---|---|---|
expression | A Boolean expression | Required. If the expression evaluates to false, the message is written in the console |
message | String or Object | Required. The message or object to write in the console |