Javascript! and!! differences

Possible duplicate:
What!! operator in javascript?

What is the difference between these two operators? There is! are of particular importance, or does it just mean that you are making two "!" operations. I know that in Javascript there are concepts of "truth" and "truthfulness", but I'm not sure that !! intended for "Truth"

+6
source share
2 answers

Spelling !! is a common way to convert a true or false variable into a true boolean.

For instance:

 var foo = null; if (!!foo === true) { // Code if foo was "truthy" } 

After the first ! applies to foo , the return value is true . Marking this value again makes it false , which means that the code inside the if block if not entered.

+7
source

!! just double!

 !true // -> false !!true // -> true 

!! is a common way to cast something to a boolean value

 !!{} // -> true !!null // -> false 
+8
source

Source: https://habr.com/ru/post/889384/


All Articles