Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does !1 and !0 mean in Javascript? [duplicate]

Tags:

javascript

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 !

like image 931
m_vdbeek Avatar asked Jul 18 '12 21:07

m_vdbeek


People also ask

What does it mean to +1 in JavaScript?

-1 means the first goes before the second, 1 means it goes after, and 0 means they're equivalent.

What is the value of 1 0 in JavaScript?

0 and 1 are type 'number' but in a Boolean expression, 0 casts to false and 1 casts to true . Since a Boolean expression can only ever yield a Boolean, any expression that is not expressly true or false is evaluated in terms of truthy and falsy. Zero is the only number that evaluates to falsy.

What does 0 mean in JavaScript?

0 is an argument passed to void that does nothing, and returns nothing. JavaScript code (as seen above) can also be passed as arguments to the void method. This makes the link element run some code but it maintains the same page.

Is it += or =+ in JavaScript?

What does += mean in JavaScript? The JavaScript += operator takes the values from the right of the operator and adds it to the variable on the left. This is a very concise method to add two values and assign the result to a variable hence it is called the addition assignment operator.


1 Answers

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.

like image 107
Anirudh Ramanathan Avatar answered Sep 19 '22 10:09

Anirudh Ramanathan