JavaScript Arithmetic # 03

JavaScript Arithmetic # 03

An arithmetic operator accepts numerical values as operands and returns a single numerical value. The numerical values can be literals or variables.
In JavaScript following are the arithmetic operators :

A typical arithmetic operation operates on two numbers, which can be literals, variables or expressions.
These numbers in an arithmetic operation are called operands. And the operation that needs to be performed between the two operands is defined by an operator

Let us discuss the arithmetic operators with example.

  1. Addition: The addition operator + adds numbers.

  2. Subtraction: The subtraction operator - subtracts numbers.

  1. Multiplication: The multiplication operator * multiplies numbers.

  1. Division: The division operator / divides numbers.

  1. Modulus: The modulus operator % returns the division remainder.

  1. Exponentiation: The exponentiation operator ** raises the first operand to the power of the second operand.

  1. Increment: The increment operator ++ increments numbers.

  1. Decrement: The decrement operator -- decrements numbers.

While doing operations of expressions in JavaScript, the focus should be given to Operator Precedence.

Operator precedence describes the order in which operations are performed in an arithmetic expression.

  1. When using parentheses, the operations inside the parentheses are computed first.

  2. Multiplication * and division / have higher precedence than addition + and subtraction - .

  3. When many operations have the same precedence (like addition and subtraction or multiplication and division), they are computed from left to right.

Click for Operator Precedence Table

In the next blog, we will discuss Basic Math in JavaScript.
If you liked this article, consider following me on Hashnode for my latest publications.