Math operators
Operator |
Meaning |
Description |
+ |
Add |
Add together to things; you can add strings and numbers together. So: 1 + 1 = 2 “Hello ” + “world” = “Hello world” “I have “ + 2 + “ apples” = “I have 2 apples” |
- |
Subtraction |
Subtract one number from another. (Note that this operator does not work with strings) So: 10 – 2 evaluates to 8 |
* |
Multiplication |
Multiplies two numbers together. (Note that this operator does not work with strings) So: 10 * 2 evaluates to 20 Multiplication has a higher precedence than addition or subtraction, so: 3 + 2 * 10 evaluates to 23 as you would probably expect if you can remember what Mrs. Button said in your grade 6 math class. |
/ |
Division |
Divides one number into another. (Note that this operator does not work with strings) So: 10 / 2 evaluates to 5 Like multiplication, division has a higher precedence than addition or subtraction, so: 6 + 10 / 2 evaluates to 11 If you guess this as well then picture Mrs. Button giving you a star sticker. |
( ) |
Grouping |
You can use parenthesis to group expressions together and override the standard operator precedence. So: (6 + 10) / 2 evaluates to 8 |