Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Falsy: Why should I use !!! instead of ! (3 instead of 1 bang) [duplicate]

Tags:

javascript

Is there any difference between !!! and !?

Found at jasmine source code in the toBeFalsy matcher.

Results from chrome devtools

!!!undefined
true
!undefined
true
!!!null
true
!null
true
!!!0
true
!0
true
like image 893
boop Avatar asked Jun 17 '15 15:06

boop


People also ask

What does 3 exclamation marks mean in JavaScript?

In JavaScript, it's a way to show that what you are evaluating is not a boolean but a truthy or falsy value. So for truthy/falsy values you either use !! or !!! . And for boolean values you either use ! or nothing. This is simply for readability.

Is {} a Falsy value?

The 7 falsy values are: 0 , 0n , null , undefined , false , NaN , and "" .

What does double bang mean in JavaScript?

So, running a bang twice on a value will first change the value to the boolean opposite, and then take that returned boolean value and flip it, again, to the opposite. In short, as stated in the TL;DR, the double-bang returns the boolean true/false association of a value.

What does '!' Mean in JavaScript?

The ! symbol is used to indicate whether the expression defined is false or not. For example, !( 5==4) would return true , since 5 is not equal to 4. The equivalent in English would be not .


1 Answers

Is there any difference between !!! and !?

No. They are the same.

Why should I use !!! instead of ! (3 instead of 1 bang)

To annoy programmers

like image 181
Drakes Avatar answered Sep 22 '22 21:09

Drakes