Tutorials References Menu

Node.js assert.strictEqual() Method

❮ Assert Module


Example

If two values are not equal (in both value and type), an error is thrown and the program is terminated:

var assert = require('assert');
assert.strictEqual(50, 50); //OK
assert.strictEqual(50, "50"); /*AssertionError: 50 === '50' */
Run example »

Definition and Usage

The assert.strictEqual() 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.

The === operator tests if the values are equal and if their types are equal.

To compare the values using the == operator, use the assert.equal() method.


Syntax

 assert.strictEqual(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.strictEqual(50, "50", "My message goes here");
Run example »

❮ Assert Module