Javascript console.assert() Method

Introduction

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'");

View in separate window

<!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
messageString or Object Required. The message or object to write in the console



PreviousNext

Related