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 !
-1 means the first goes before the second, 1 means it goes after, and 0 means they're equivalent.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With