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 returns a boolean value, which depends on the truthiness of the given expression.
In general, logical not(!) determines the “truth” of what a value is not:
- The truth is that false is not true (that’s why !false results in true)
- The truth is that true is not false (that’s why !true results in false)
!! determines the “truth” of what a value is not not:
- The truth is that true is not not true (that’s why !!true results in true)
- The truth is that false is not not false (that’s why !!false results in false)
Example-1: This example checks the truthyness of the boolean value true.
<script> // Write Javascript code here var n1; /* checking truthyness of the boolean value true. */ n1 = !!true; document.write(n1); </script> |
Output:
true
Example-2: This example checks the falsyness of the boolean value false.
<script> // Write Javascript code here var n1; // checking falsyness of the boolean value false. n1 = !!false; document.write(n1); </script> |
Output:
false
Example-3: This example checks the truthyness or falsyness of a given string.
<script> // Write Javascript code here var n1; // checking the truthyness or falsyness of a given string. n1 = !!"Javascript programming"; document.write(n1); </script> |
Output:
true
Example-4: This example checks the truthyness or falsyness of a given object.
<script> // Write Javascript code here var n1; // checking the truthyness // or falsyness of a given object. n1 = !!{ articles: 70 }; document.write(n1); </script> |
Output:
true
Recommended Posts:
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript | typeof operator
- Arrow operator in ES6 of JavaScript
- JavaScript | Spread Operator
- Instanceof operator in JavaScript
- JavaScript | ‘===’ vs ‘==’Comparison Operator
- Difference between != and !== operator in JavaScript
- Difference between == and === operator in JavaScript
- How to get negative result using modulo operator in JavaScript ?
- Ternary operator / Question mark and colon in JavaScript
- Why overriding both the global new operator and the class-specific operator is not ambiguous?
- Ternary operator vs Null coalescing operator in PHP
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- How to compare two JavaScript array objects using jQuery/JavaScript ?
- PHP | $ vs $$ operator
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



