Bảng điều khiển khẳng định ()
❮
❯
Các ví dụ
Viết tin nhắn vào bảng điều khiển:
console.assert(x + y == 11, "Expression returned false");
Ghi một đối tượng vào bảng điều khiển:
const myObj = {firstname:"John", lastname:"Doe"};
console.assert(x + y == 11, myObj);
Thêm ví dụ bên dưới.
Định nghĩa và Cách sử dụng
Phương assert()
thức ghi một thông báo vào bảng điều khiển nếu một biểu thức đánh giá là 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. |
Các ví dụ khác
Kiểm tra một phần tử:
console.assert(document.getElementById("demo"), "You have no element with ID 'demo'");
Ghi một mảng vào bảng điều khiển:
const myArr = ["Orange", "Banana", "Mango", "Kiwi" ];
console.assert(x + y = 11, myArr);
Hỗ trợ trình duyệt
console.assert()
được hỗ trợ trong tất cả các trình duyệt:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
❮
❯