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).
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
Operand | Operator | Operand | Result |
5 | + | 8 | 13 |
10 | % | 3 | 1 |
8 | / | 4 | 2 |
10 | * | 2 | 20 |
To know more about JavaScript operators, click here.
https://www.welookups.com/js/js_arithmetic.html
ReplyDelete