The values in variables are stored not only for displaying them later but also for performing different operations with them. To perform operations with the values of variables you need operators.
var a = 3; // assign the value 3 to a
var b = 8; // assign the value 8 to b
var c = a + b; // assign the value 11 to c (a + b)
Like you want to add the values of two variables. For this, you will use the addition (+) operator. And if you want to compare the values of two variables, then you use relational operators. Let’s know about some important terms before knowing more about the operators.
The variables that operators apply or the variables with which they are used are called operands. See the statement written below.
c = a+b;
Types of Operators
There are two types of operators unary and binary. Unary operators are those operators who apply only on one variable. Like (~) is NOT operator.
This operator is applied with only one variable. Binary operators are those operators whose execution requires two operators. Like (+) operator. You cannot use this operator with any single variable. This variable requires two operands to execute.
Arithmetic operators are used to performing arithmetic operations.
|+||It adds values of two or more variables|
|–||Subtract value of one variable from other variables value|
|*||Multiply values of two variables|
|/||Divide value of one variable by value of another variable.|
|%||Get the remainder after division|
|**||Value of first variable raise to power to value of second variable|
Relative operators can compare the values of two variables. These operators are mostly used in control statements when you try to build logic. Like which variable is big or small.
|==||This operator compares the values of the two variables for equality.|