
- Node.js - Home
- Node.js - Introduction
- Node.js - Environment Setup
- Node.js - First Application
- Node.js - REPL Terminal
- Node.js - Command Line Options
- Node.js - Package Manager (NPM)
- Node.js - Callbacks Concept
- Node.js - Upload Files
- Node.js - Send an Email
- Node.js - Events
- Node.js - Event Loop
- Node.js - Event Emitter
- Node.js - Debugger
- Node.js - Global Objects
- Node.js - Console
- Node.js - Process
- Node.js - Scaling Application
- Node.js - Packaging
- Node.js - Express Framework
- Node.js - RESTFul API
- Node.js - Buffers
- Node.js - Streams
- Node.js - File System
- Node.js MySQL
- Node.js - MySQL Get Started
- Node.js - MySQL Create Database
- Node.js - MySQL Create Table
- Node.js - MySQL Insert Into
- Node.js - MySQL Select From
- Node.js - MySQL Where
- Node.js - MySQL Order By
- Node.js - MySQL Delete
- Node.js - MySQL Update
- Node.js - MySQL Join
- Node.js MongoDB
- Node.js - MongoDB Get Started
- Node.js - MongoDB Create Database
- Node.js - MongoDB Create Collection
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB Query
- Node.js - MongoDB Sort
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js Modules
- Node.js - Modules
- Node.js - Built-in Modules
- Node.js - Utility Modules
- Node.js - Web Module
Node.js assert.notStrictEqual() Function
The Node.js assert.notStrictEqaul() function is an inbuilt function of the assert module of Node.js. It is used to verify the strict equality of the given parameters.
This function is used to check if two values are not equal. It checks for both type and value equality, unlike the strict equality operator (===) which only checks for value equality. This means that it will return true if two variables have different types but the same value, or false if they have the same type but a different value.
The "!=" operator will be used by this function to test both the actual and expected parameters. This function will throw AssertionError if the values are equal. Otherwise, if the values are not the same, the function won't produce anything. This function isidentical to the Node.js assert.notStrictEqual() function.
Syntax
Following is the syntax of Node.js assert.notStrictEqaul() function −
assert.notStrictEqual(actual, expected[, message]);
Parameters
This function accepts three parameters. The same are described below.
actual − (required) The value passed in this parameter will be evaluated. The value can be of any type.
expected − (required) The value passed in this parameter will be compared to the actual value. The value can be of any type.
message − (optional) String or Error type can be passed as an input into this parameter.
Return Value
This function will return the AssertionError on the terminal if both actual and expected are matched.
Example
In the following example, we are passing two distinct integers to the actual and expected parameters of the Node.js assert.notStrictEqual()function.
const assert = require('assert'); var N1 = 1; var N2 = 2; assert.notEqual(N1, N2, "Both values are Not EQUAL");
Output
Since both the input parameters result differently, the function doesn't throw an AssertionError to the output.
// Returns nothing
Example
In the example below, we are passing two identical integers to the actual and expected parameters of the function.
const assert = require('assert'); var Num1 = 65; var Num2 = 65; assert.notEqual(Num1, Num2, "Both integers are EQUAL");
Output
Since both the input parameters result the same, the function will throw an AssertionError along with the text in the message parameter.
assert.js:79 throw new AssertionError(obj); ^ AssertionError [ERR_ASSERTION]: Both integers are EQUAL at Object.<anonymous> (/home/cg/root/639c38b0b0aed/main.js:6:8) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
Example
In the following example below, we are creating two objects with distinct properties. Then we are passing both the objects as actual and expected to the function and also passed a text to the message parameter.
const assert = require('assert'); var object1 = { Name : 'Pushpa', Designation : 'Smuggler' }; var object2 = { Name : 'Raj', Designation : 'Syndicate Head' }; assert.notEqual(object1, object2, "Both the objects are NOT EQUAL");
Output
As the actual and expected results are different, the function will not throw an AssertionError when the code is compiled and executed.
// Returns nothing
Example
In the example below, we are passing two identical strings as inputs to the actual and expected parameters.
const assert = require('assert'); assert.notEqual('The rise', 'The rise', "Both the strings are EQUAL");
Output
Since the actual and expected results are the same, the function will throw an AssertionError to the output when the code is compiled and executed.
assert.js:79 throw new AssertionError(obj); ^ AssertionError [ERR_ASSERTION]: Both the strings are EQUAL at Object.<anonymous> (/home/cg/root/639c3b5c17b34/main.js:3:8) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)