HTML DOM console.assert() method
Example
If the first argument is false, output information to the console:
console
.
assert
(
document
.
getElementById
(
"
demo
"
)
,
"
No element with ID 'demo'
"
)
;
Try it »
Definition and Usage
The console.assert() method outputs information to the console when the first argument is false.
Syntax
console.assert(expression, message)
Browser support
The numbers in the table indicate the first browser version that supports this method.
| Method | |||||
|---|---|---|---|---|---|
| console.assert() | Yes | Yes | 28 | Yes | Yes |
Parameter Description
| Parameters | Type | Description |
|---|---|---|
| Expression | Boolean expression | Required. A boolean expression that returns true or false. |
| Information | String or object | Required. The information or object to write to the console. |
More examples
Example
Write an object to the console:
var
myObj
=
{
name
:
"
Runoob Tutorial
"
,
site
:
"
www.runoob.com
"
}
;
console
.
assert
(
document
.
getElementById
(
"
demo
"
)
,
myObj
)
;
Try it »
Example
Write an array to the console:
var
myArr
=
[
"
"
,
"
Taobao
"
,
"
Runoob
"
,
"
"
]
;
console
.
assert
(
document
.
getElementById
(
"
demo
"
)
,
myArr
)
;
Try it »
Console object