Is the !! (not not) operator in JavaScript equivalent to reverse process of not operator?

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

Yes, the not not operator is the reverse process of not operator. If any value is true then single ! (not) will return false and !! will return opposite value (true).

The not operator −

var flag=true;
console.log(!flag);

The not not operator −

var flag=true;
console.log(!!flag);

Example

Following is the code −

var flag=true;
console.log("The result of single !=")
console.log(!flag);
console.log("The result of single !!=")
console.log(!!flag)

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo247.js

Output

This will produce the following output on console −

PS C:\Users\Amit\javascript-code> node demo247.js
The result of single !=
false
The result of single !!=
True
raja
Published on 09-Nov-2020 06:25:30
Advertisements