Konsol onaylaması()
Örnekler
Konsola bir mesaj yazın:
console.assert(x + y == 11, "Expression returned false");
Konsola bir nesne yazın:
const myObj = {firstname:"John", lastname:"Doe"};
console.assert(x + y == 11, myObj);
Aşağıda daha fazla örnek.
Tanım ve Kullanım
Bir assert()
ifade olarak değerlendirilirse, yöntem konsola bir mesaj yazar false
.
Sözdizimi
console.assert(expression, message)
parametreler
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. |
Daha fazla örnek
Bir öğe olup olmadığını kontrol edin:
console.assert(document.getElementById("demo"), "You have no element with ID 'demo'");
Konsola bir dizi yazın:
const myArr = ["Orange", "Banana", "Mango", "Kiwi" ];
console.assert(x + y = 11, myArr);
Tarayıcı Desteği
console.assert()
tüm tarayıcılarda desteklenir:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |