Home > Web Front-end > JS Tutorial > Instructions for using the console.assert method in node.js_node.js

Instructions for using the console.assert method in node.js_node.js

WBOY
Release: 2016-05-16 16:27:55
Original
1448 people have browsed it

Method description:

This method is the same as assert.ok(). If the expression evaluates to false, an AssertionError will be thrown along with the message

Grammar:

Copy code The code is as follows:

console.assert(expression, [message])

Receive parameters:

expression                                                  

message Error message

Example:

Copy code The code is as follows:
var a = 0;
console.assert(a == 1, 'error!');

Source code:

Copy code The code is as follows:
Console.prototype.assert = function(expression) {
if (!expression) {
var arr = Array.prototype.slice.call(arguments, 1);
​ require('assert').ok(false, util.format.apply(this, arr));
}
};

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template