x


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...

more ▼

asked Oct 07 '10 at 11:08 PM

kroltan bahuman gravatar image

kroltan bahuman
60 1 2 8

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Oct 07 '10 at 11:11 PM

Marowi gravatar image

Marowi
4.9k 4 14 53

i imagined this, but when i tested, it didn't worked. (i was using !Input.GetButtonDown("Fire3") as the condition)

Oct 07 '10 at 11:17 PM kroltan bahuman

btw: thank you!

Oct 07 '10 at 11:17 PM kroltan bahuman

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.

Oct 07 '10 at 11:33 PM Marowi
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x41
x2

asked: Oct 07 '10 at 11:08 PM

Seen: 2136 times

Last Updated: Nov 12 '10 at 05:16 AM