Friday 30 September 2016

JavaScript Arithmetic Operators

js-pc.jpg

Arithmetic operators perform arithmetic operations on numbers (literals/variables — also known as operands). There are a number of JavaScript operators including: + (Addition), - (Subtraction), * (Multiplication), / (Division), % (Modulus), ++ (Increment), -- (Decrement).

JavaScript Operations

A typical and simple JavaScript operation has two numbers (operands) to work on. Take a look at the example below:

 var sum = 10 + 20; document.write(sum); 

In the snippet of code above, a variable “sum” was declared and the sum of 10 and 20 is assigned to it, on the next line, the result (30) is printed to the screen.In the same manner, we can use the arithmetic operators on variables as well, say for example:

 var a = 2; var d = 5; var product = a * d; document.write(product); 

In the snippet above, a value, 2, is assigned to variable a, 5 assigned to d, and the product of variables a and d (in this case, 2 and 5) is assigned to another variable “product” and printed to the screen.

Some Analysis

OperandOperatorOperandResult
5+813
10%31
8/42
10*220

To know more about JavaScript operators, click here.

1 comment:

Your response mean a lot to us. Drop one.