- Home /
What does the "!" character do? (JavaScript)
what does the exclamation mark (!) does when placed before something (in a if, for example)? I can't find out...
Answer by · Oct 07, 2010 at 11:11 PM
It means "not".
The 'exclamation mark' (!) is often referred to as the 'logical NOT operator' (Javascript reference page).
Some examples...
These two have the same outcome, but most people prefer to write it the second way:
if ( !(variable == 10) ) // if the inner statement is not true
if ( variable != 10 ) // if the variable does not equal 10
It's also useful for 'flipping' bools - i.e. setting it to false if it's true, and setting it to true if it's false:
boolean = !boolean;
Hope this helps. Let me know if you need further explanation.
i imagined this, but when i tested, it didn't worked. (i was using !Input.GetButtonDown("Fire3") as the condition)
No worries, if this answers your question please mark it as correct (click the tick). As for why your input check wasn't working, perhaps you could ask a new question with your whole script and I can take a look.
Your answer

Follow this Question
Related Questions
In Javascript, can I reverse a boolean as so: boolean = !boolean 1 Answer
how do i use 'And' and 'Or' in UnityScript 2 Answers
Javascript And operator not working 1 Answer
cannot be applied to operands 0 Answers
Bitwise Operators 3 Answers