Operations
What if you wanted to do some math in your code? Or check if a certain condition is true? You can use operators!
There are multiple types of operations,
Math Operations
These are used to do math with data.
Addition
Adds two numbers.
a + b
Subtraction
Subtracts two numbers.
a - b
Multiplication
Multiplies two numbers.
a * b
Division
Divides two numbers.
a / b
Modulus
Divides two numbers, but gets the remainder.
a % b
Unary Operations
These are used to modify variables.
+=
Adds n to the variable.
num += 3
-=
Subtracts n from the variable.
num -= 16
*=
Multiplies the variable by n.
num *= 3
/=
Divides the variable by n.
num /= 10
Logic Operators
Logic operators compare values, letting you do logic as the name suggests. For here, you'd use them with if-statements, which we'll cover soon.
== (Equals)
value == value
Checks if the two values are equal.
true == true // returns true 1 == 1 // returns true 6 == 9 // returns false
!= (Not equals)
value != value
Returns if the two values are NOT equal.
true != false // returns true 2 != 2 // returns false
&& (And)
condition && condition
Checks if both of the conditions are true.
true && true // returns true
2 == 4 // returns false
|| (Or)
condition || condition
Gives you if one of the conditions is true.
1 == 2 || 3 > 2 // returns true because 3 > 2
! (Not)
!condition
Gives you if the condition is false.
!(2 == 4) // returns true !(3 == 3) // returns false
Last updated