English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
If assert is false ,console.assert()The method will write the error message to the console.
If assert is true, nothing will happen.
console.assert(assertion, 'message')
console.assert(document.getElementById("result"), 'No ID element'result'Test and see‹/›
All browsers fully support the console.assert() method:
Method | |||||
console.assert() | is | is | is | is | is |
Parameter | Description |
---|---|
assertion | Any boolean expression. IfassertIf false, the message is written to the console |
message | String or object to be written in the console |
This example writes a string to the console:
console.assert(false, "Hello world!!!");Test and see‹/›
This example writes an object to the console:
var myObj = { str: "Some text", id: 12 }; console.assert(document.getElementById("result"), myObj);Test and see‹/›
This example writes an array to the console:
var arr = ["Item1", "Item2", "Item3", "Item4"]; console.assert(document.getElementById("result"), arr);Test and see‹/›