翻譯不完整。請協助 翻譯此英文文件

如果斷言(assertion)為非(false),主控台會顯示錯誤訊息;如果斷言為是(true),則不發生任何事。

註: This feature is available in Web Workers.

注意在 Node.js 內 console.assert() 方法的實做,與瀏覽器並不相同。

瀏覽器內呼叫 falsy 的 console.assert() 斷言出現 message,但不會中斷程式碼的執行。然而在 Node.js 裡面,falsy 斷言會拋出 AssertionError 錯誤。

語法

console.assert(assertion, obj1 [, obj2, ..., objN]);
console.assert(assertion, msg [, subst1, ..., substN]); // c-like message formatting

參數

assertion
布林表達式。如果斷言為非,訊息會出現在主控台上。
obj1 ... objN
要印出來的 JavaScript 物件名單。 The string representations of each of these objects are appended together in the order listed and output.
msg
包含零個以上的 JavaScript 替代(substitution)字串。
subst1 ... substN
JavaScript objects with which to replace substitution strings within msg. This parameter gives you additional control over the format of the output.

請參見 consoleOutputting text to the console 以獲取詳細資訊。

規範

Specification Status Comment
Console API
The definition of 'console.assert()' in that specification.
Living Standard 初始定義

瀏覽器相容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support YesEdge Full support 12Firefox Full support 28IE Full support YesOpera Full support YesSafari Full support YesWebView Android ? Chrome Android ? Edge Mobile ? Firefox Android Full support 28Opera Android ? Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

參見

文件標籤與貢獻者

此頁面的貢獻者: iigmir
最近更新: iigmir,