Bảng điều khiển khẳng định()
Ví dụ
Viết một tin nhắn đến bàn điều khiển:
console.assert(x + y == 11, "Expression returned false");
Hãy tự mình thử »Viết một đối tượng vào bàn điều khiển:
const myObj = {firstname:"John", lastname:"Doe"};
console.assert(x + y == 11, myObj);
Hãy tự mình thử »Thêm ví dụ dưới đây.
Sự miêu tả
Phương thức assert()
ghi một thông báo tới bảng điều khiển nếu một biểu thức có giá trị false
.
Cú pháp
console.assert( expression , message )
Thông số
Parameter | Description |
expression | Required. Any expression. If the expression evaluates to false , a message
is written in the console. |
message | Required. The message to write in the console. |
Thêm ví dụ
Kiểm tra một phần tử:
console.assert(document.getElementById("demo"), "You have no element with ID 'demo'");
Hãy tự mình thử »Viết một mảng vào bàn điều khiển:
const myArr = ["Orange", "Banana", "Mango", "Kiwi" ];
console.assert(x + y == 11, myArr);
Hãy tự mình thử »Hỗ trợ trình duyệt
console.assert()
được hỗ trợ trong tất cả các trình duyệt:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |