JavaScript console.assert() Method

You are Here:

JavaScript console.assert() Method

The console.assert() method writes an error message to the console if the assertion is false. If the assertion is true, nothing happens.

Note: This feature is available in Web Workers.


HTML Online Editor
<!DOCTYPE html> <html> <body> <script> console.assert(true, "I will not display"); console.assert(false, "I will display"); </script> </body> </html>


console.assert(expression, msg)

Parameter Values

expressionRequiredAny boolean expression. If the assertion is false, the message is written to the console.
msgRequiredA JavaScript string containing zero or more substitution strings.

Real Time Example

In the following example, we will try to get an id of an element which is not available.


HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var x = document.getElementById("point"); console.assert(x, "id = 'point' not found"); </script> </body> </html>


Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author