Node.js assert.equal() Method
Example
If two values are not equal, an error is thrown and the program is terminated:
var assert = require('assert');
assert.equal(50, 50); //OK
assert.equal(50,
"50"); //OK
assert.equal(50, 70); /*AssertionError: 50 == 70
*/
Run example »
Definition and Usage
The assert.equal() method tests if two values are equal, using the == operator.
If the two values are not equal, an assertion failure is being caused, and the program is terminated.
To compare the values using the === operator, use the assert.strictEqual() method.
Syntax
assert.equal(value1, value2, message);
Parameter Values
Parameter | Description |
---|---|
value1 | Required. Specifies the first value to be compared |
value2 | Required. Specifies the second value to be compared |
message | Optional. Specifies the error message to be assigned to the AssertionError. If omitted, a default message is assigned |
Technical Details
Return Value: | None |
---|---|
Node.js Version: | 0.1.21 |
More Examples
Example
Using the message parameter:
var assert = require('assert');
assert.equal(50, 70, "My message goes here");
Run example »
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.