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


  • value <any> 测试其是否为真值的值。
  • ...message <any> 除了 value 之外的所有参数都用作错误消息。

console.assert() 会在 value假值 或未提供时写入一条消息。它仅写入消息,不会以其他方式影响执行。输出总是以“Assertion failed”开头。如果提供,message 会使用 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