console.assert(value[, ...message])


版本历史
版本变更
v10.0.0

该实现现在符合规范并且不再抛出错误。

v0.1.101

新增于: v0.1.101

  • value <any> 测试为真的值。

    \value <any> The value tested for being truthy.

  • ...message <any> 除了 value 之外的所有参数都用作错误消息。

    \...message <any> All arguments besides value are used as error message.

如果 value非真值 或省略,则 console.assert() 写入消息。它只写入一条消息,不会影响执行。输出始终以 "Assertion failed" 开头。如果提供,则使用 util.format() 格式化 message

\console.assert() writes a message if value is falsy or omitted. It only writes a message and does not otherwise affect execution. The output always starts with "Assertion failed". If provided, message is formatted using util.format().

如果 value真值,则什么也不会发生。

\If value is truthy, nothing happens.

console.assert(true, 'does nothing');
console.assert(false, 'Whoops %s work', 'didn\'t');
// Assertion failed: Whoops didn't work
console.assert();
// Assertion failed 

AltStyle によって変換されたページ (->オリジナル) /