The exclamation character is the NOT operator !
The NOT operator is used to evaluate an expression to true or false.
Here's the NOT operator using a simple if statement format:
if (!(condition1)) {
doSomething();
}
Here's the NOT operator using a if-then-else statement format:
if (!(condition1)) {
doSomething();
}
else {
doSomethingElse();
}
The method doSomething() will only execute if the condition in the if statement evaluates to false.
Let's take a look at another, more concrete example:
if (!(respawnRemaining >= 1)) {
gameOver();
}
The method gameOver() will only execute if respawnRemaining is NOT greater than or equal to 1.
In the following example, we use an if-then-else statement:
if (!(respawnRemaining >= 1)) {
gameOver();
}
else {
respawn();
}
If respawnRemaining is NOT greater than or equal to 1, the gameOver method will execute. If it is greater than or equals to 1, the respawn method will execute.
Also see
&& Operator (AND)
|| Operator (OR)






