คอนโซลยืนยัน ()
❮ การ
❯
ตัวอย่าง
เขียนข้อความไปยังคอนโซล:
console.assert(x + y == 11, "Expression returned false");
เขียนวัตถุไปยังคอนโซล:
const myObj = {firstname:"John", lastname:"Doe"};
console.assert(x + y == 11, myObj);
ตัวอย่างเพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
เมธอด จะassert()
เขียนข้อความไปยังคอนโซลหากนิพจน์ประเมินfalse
เป็น
ไวยากรณ์
console.assert(expression, message)
พารามิเตอร์
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. |
ตัวอย่างเพิ่มเติม
ตรวจสอบองค์ประกอบ:
console.assert(document.getElementById("demo"), "You have no element with ID 'demo'");
เขียนอาร์เรย์ไปยังคอนโซล:
const myArr = ["Orange", "Banana", "Mango", "Kiwi" ];
console.assert(x + y = 11, myArr);
รองรับเบราว์เซอร์
console.assert()
รองรับในทุกเบราว์เซอร์:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
❮ การ
❯