What is the !! (not not) operator in JavaScript?

Explanation

There is no such operator in JavaScript. It is just the not operator which is used twice.

Here we will convert Object to boolean. If it was falsely for e.g. 0nullundefined, etc.. It will be false, otherwise, true.

!oObject  // inverted boolean
!!oObject // non inverted boolean so true boolean representation

So !! this is not any type of operator, But instead, it is just the ! operator twice.

Here we  will take a Real World Example “Test IE version”:

const isIE8 = !! navigator.userAgent.match(/MSIE 8.0/);  
console.log(isIE8); // returns true or false 

If you do use not ⇒

console.log(navigator.userAgent.match(/MSIE 8.0/));  
// returns either an Array or null  

But if you use not it will be ⇒

console.log(!!navigator.userAgent.match(/MSIE 8.0/));  
// returns either true or false

 

Also read, Undo a Git merge that hasn’t been pushed yet

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *