Basic Math Operators

In computer science there are just a few universal operations, basic math operators seem to be one of them. The operators are as follows:

  1. Addition +
  2. Subtraction –
  3. Multiplication *
  4. Division /
  5. Parenthesis ()


They are used just like you learned in school.

JavaScript

// To get the results below open your browsers developer tools, 
// hit F12 on the keyboard. Then select the console and you 
// will be able to type the code below

1 + 2
3

3 - 2
1

2 * 3
6

6 / 2
3

(1 + 1)
2

For these actions the Order of Operations applies. So, Parenthesis are evaluated first, then Multiplication and Division, and finally Addition and Subtraction. All evaluations are done from left to right in operations order.

JavaScript

1 + 2 * 3
7

(1 + 2) * 3
9

(((1 + 2) * 3) + 6) * 7
105

That is all there is to the basic math operations in programming. I hope you learned something from this, but if not please look at some of the other articles as they are more advanced and may lend you some insight in the the world of software development.

Comments are closed.