console.assert(value[, ...message])
如果 value
为非真或省略,则 console.assert()
会写入消息。
它只写入消息,不影响执行。
输出始终以 "Assertion failed"
开头。
如果提供了 message
,则使用 util.format()
格式化它。
如果 value
为真,则什么也不会发生。
console.assert(true, '什么都不做');
console.assert(false, '%s 工作', '无法');
// Assertion failed: 无法工作
console.assert();
// Assertion failed
value
<any> The value tested for being truthy....message
<any> All arguments besidesvalue
are used as error 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()
.
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