xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js assert

console.assert

The console.assert() method writes an error message to the console if the assertion is false.
If the assertion is true, nothing happens.

https://console.spec.whatwg.org/#assert

https://developer.mozilla.org/en-US/docs/Web/API/console/assert

console.assert(assertion, obj1 [, obj2, ..., objN]);

console.assert(assertion, msg [, subst1, ..., substN]); 
// C-like message formatting

demos

const errorMsg = 'the # is not even';
for (let number = 2; number <= 5; number += 1) {
    console.log('the # is ' + number);
    console.assert(number % 2 === 0, {number: number, errorMsg: errorMsg});
    // or, using ES2015 object property shorthand:
    // console.assert(number % 2 === 0, {number, errorMsg});
}
// output:
// the # is 2
// the # is 3
// Assertion failed: {number: 3, errorMsg: "the # is not even"}
// the # is 4
// the # is 5
// Assertion failed: {number: 5, errorMsg: "the # is not even"}

Web Workers

https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API

Node.js

https://nodejs.org/api/assert.html

refs



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


原文地址:https://www.cnblogs.com/xgqfrms/p/12687363.html