Instructions for using the console.assert method in node.js
- 2020-03-30 04:36:23
- OfStack
Method description:
This method is the same as assert. Ok (). If the expression evaluates to false, an AssertionError will be thrown along with a message.
Grammar:
console.assert(expression, [message])
Receiving parameters:
Expression expression
Message Error message
Example:
var a = 0;
console.assert(a == 1, 'error!');
Source:
Console.prototype.assert = function(expression) {
if (!expression) {
var arr = Array.prototype.slice.call(arguments, 1);
require('assert').ok(false, util.format.apply(this, arr));
}
};