What does !1 and !0 mean in Javascript?

Javascript

Javascript Problem Overview


> Possible Duplicate:
> return !1 in javascript

In a JavaScript file I had to read today, there was a line where a variable was declared like a factorial, like this :

var myVariable = !1;

and then something similar was used as parameter in a function like this :

return variable.myFunction(!0);

Can anyone explain me what the exclamation mark means in this context and eventually, why this is generally used for (benefits) ?

Thank you in advance !

Javascript Solutions


Solution 1 - Javascript

The ! is the boolean NOT operator.

NOT (!): toggles a statement from true to false or from false to true.

!0 = true
!1 = false

This is a brilliant introduction to boolean operators and their use in javascript.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionm_vdbeekView Question on Stackoverflow
Solution 1 - JavascriptAnirudh RamanathanView Answer on Stackoverflow