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

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

javascript operator
boolean vs !! javascript
short-circuit evaluation javascript
ternary operator javascript
not greater than javascript
logical operators
javascript double question mark
javascript exclamation point operator

I saw some code that seems to use an operator I don't recognize, in the form of two exclamation points, like so: !!. Can someone please tell me what this operator does?

The context in which I saw this was,

this.vertical = vertical !== undefined ? !!vertical : this.vertical;

Coerces oObject to boolean. If it was falsey (e.g. 0, null, undefined, etc.), it will be false, otherwise, true.

!oObject  //Inverted boolean
!!oObject //Non inverted boolean so true boolean representation

So !! is not an operator, it's just the ! operator twice.

Real World Example "Test IE version":

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

If you ⇒

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

but if you ⇒

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

What is the !! (not not) operator in JavaScript?, Converts Object to boolean . If it was falsey (e.g. 0 , null , undefined , etc.), it will be false , otherwise, true . !oObject // inverted boolean !!oObject // non inverted  Unless you have been using JavaScript for a while this may look like some advanced VooDoo. But it is really a shorthand way to convert any value to a boolean. The syntax leverages a little sorcery by doubling up the not operator. So let's dive a little deeper into the JavaScript not logical operator and examine truthfulness in JavaScript.


It's a horribly obscure way to do a type conversion.

! is NOT. So !true is false, and !false is true. !0 is true, and !1 is false.

So you're converting a value to a boolean, then inverting it, then inverting it again.

// Maximum Obscurity:
val.enabled = !!userId;

// Partial Obscurity:
val.enabled = (userId != 0) ? true : false;

// And finally, much easier to understand:
val.enabled = (userId != 0);

What is the !! (not not) operator in JavaScript?, The !!(not not) is the repetition of the unary logical operator not(!) twice. The double negation(!!) operator calculates the truth value of a value. This operator  (not not) operator in JavaScript? The !!(not not) is the repetition of the unary logical operator not(!) twice. The double negation(!!) operator calculates the truth value of a value. This operator returns a boolean value, which depends on the truthiness of the given expression.


!!expr returns a Boolean value (true or false) depending on the truthiness of the expression. It makes more sense when used on non-boolean types. Consider these examples, especially the 3rd example and onward:

          !!false === false
           !!true === true

              !!0 === false
!!parseInt("foo") === false // NaN is falsy
              !!1 === true
             !!-1 === true  // -1 is truthy

             !!"" === false // empty string is falsy
          !!"foo" === true  // non-empty string is truthy
        !!"false" === true  // ...even if it contains a falsy value

     !!window.foo === false // undefined is falsy
           !!null === false // null is falsy

             !!{} === true  // an (empty) object is truthy
             !![] === true  // an (empty) array is truthy; PHP programmers beware!

Logical operators, empty string ( "" or '' or `` );; undefined . Even though the && and || operators can be used with operands that are not Boolean values, they  Which explains that if both of conditions are FALSE or 0, the return is FALSE or 0. In fig.-2 of the picture, one of the taps are closed, even then, the water is not flowing down. Which explains that even if any of conditions are FALSE or 0, the return is FALSE or 0. fig.-3 of the picture resembles CASE -2.


JS Double Bang, Although not the most common use of a logical operator in JavaScript, the “​double bang” or double exclamation mark “!!” recently caught my attention. Let's dive  Even though the && and || operators can be used with operands that are not Boolean values, they can still be considered boolean operators since their return values can always be converted to boolean primitives. To explicitly convert their return value (or any expression in general) to the corresponding boolean value, use a double NOT operator


!! converts the value to the right of it to its equivalent boolean value. (Think poor man's way of "type-casting"). Its intent is usually to convey to the reader that the code does not care what value is in the variable, but what it's "truth" value is.

Javascript “Bang, Bang. I Shot You Down”, In Javascript, the exclamation mark (“!”) symbol, called a “bang,” is the logical “not​” operator. Placed in front of a boolean value it will reverse the value, returning  There are three logical operators in JavaScript: || (OR), && (AND), ! Although they are called “logical”, they can be applied to values of any type, not only boolean. Their result can also be of any type. Let’s see the details. The “OR” operator is represented with two vertical line symbols: In classical programming, the logical OR is


What is the !! (not not) operator in JavaScript?, The double negation(!! ) operator is the! Operator twice and calculates the truth value of a value. It returns a Boolean value, which depends on  Operator Description == equal to === equal value and equal type!= not equal!== not equal value or not equal type > greater than < less than >= greater than or equal to <= less than or equal to? ternary operator


JavaScript Double Negation (!!) Trick or Trouble?, See speed tests below. !! is not an operator. It's just the ! operator twice. Examples: success = !! Comparison and Logical operators are used to test for true or false. Comparison operators are used in logical statements to determine equality or difference between variables or values. Given that x = 5, the table below explains the comparison operators: Comparison operators can be used in conditional statements to compare values and take


JavaScript Comparison and Logical Operators, Comparison operators are used in logical statements to determine equality or difference between variables or values. not equal value or not equal type, x !== Using Logical Operators with Non-Boolean Values. In JavaScript, the logical operators have different semantics than other C-like languages, though. They can operate on expressions of any type, not just booleans. Also, the logical operators do not always return a boolean value, as the specification points out in section 12.12: