Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

Node.js assert.notEqual() Method

❮ Assert Module


Example

If two values are equal, an error is thrown and the program is terminated:

var assert = require('assert');
assert.notEqual(50, 70); //OK
assert.notEqual(50, 50); /*AssertionError: 50 != 50 */
Run example »

Definition and Usage

The assert.notEqual() method tests if two values are NOT equal, using the != operator.

If the two values are equal, an assertion failure is being caused, and the program is terminated.

To compare the values using the stricter !== operator, use the assert.notStrictEqual() method.


Syntax

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

❮ Assert Module