Any value on which an operator performs some action is called an operand.
An expression may contain one operand and one operator (called a unary operator) or two operands separated by one operator (called a binary operator). Many of the same symbols are used in a variety of operators.
The combination and order of those operator symbols are what distinguish their powers. In simple words, an operator is the one operating the operand.
These operators are used to operate mathematical operations between numeric operands.
|+||Used to add two numeric operands.|
|-||Used to subtract right operand from left operand|
|*||Used to multiply two numeric operands.|
|/||Used to divide left operand by right operand.|
|%||Modulus operator. It returns remainder of two operands.|
|++||Increment operator. It Increases operand value by one.|
|--||Decrement operator. It decreases value by one.|
var a = 2, b = 4; a + b; //returns 6 b - a; //returns 2 a * b; //returns 8 b / a; //returns 2 a % 2; //returns 1 a++; //returns 3 a--; //returns 1
Note : + Operator executes a series of operations provided that one of the operands is of string type. This example will help you understand the working of + Operator on operands of various data types.
var w = 5, x = "Hello ", y = "World!", z = 10; w + x; // "5Hello " x + y; // "Hello World!" w + z; // 15
You have a wide selection of comparison operators to choose from, depending on the kind of test you want to apply to the two operands.
There are basically 4 ways by which the equality is tested that are listed as follows:
All the various types of comparison operators are mentioned in the table below:
|==||Is equal to||11==22 = false|
|===||Identical (equal and of same type)||11==22 = false|
|!=||Not equal to||10!=20 = true|
|!==||Not Identical||22!==22 = false|
|>||Greater than||22>12 = true|
|>=||Greater than or equal to||22>=12 = true|
|<||Less than||22<12 = false|
|<=||Less than or equal to||22<=12 = false|
For numeric values, the results are the same as those you would expect from your high school algebra class.
10 == 10 // true 10 == 10.0 // true 9 != 10 // true 9 > 10 // false 9.99 <= 9.98 // false
The bitwise operators carryout bitwise operations on the operands. Here are the bitwise operators:
|&||Bitwise AND||(10==20 & 20==33) = false|
||||Bitwise OR||(10==20 | 20==33) = false|
|^||Bitwise XOR||(10==20 ^ 20==33) = false|
|~||Bitwise NOT||(~10) = -10|
|<<||Bitwise Left Shift||(10<<2) = 40|
|>>||Bitwise Right Shift||(10>>2) = 2|
|>>>||Bitwise Right Shift with Zero||(10>>>2) = 2|
All the various types of Logical operators are mentioned in the table below:
|&&||Logical AND||(12==22 && 22==33) = false|
|||||Logical OR||(12==22 || 22==33) = false|
|!||Logical Not||!(12==22) = true|
All the various types of Assignment operators are mentioned in the table below:
|=||Assign||10+10 = 20|
|+=||Add and Assign||var a=10; a+=20; Now a = 30|
|-=||Subtract and assign||var a=20; a-=10; Now a = 10|
|*=||Multiply and assign||var a=10; a*=20; Now a = 200|
|/=||Divide and assign||var a=10; a/=2; Now a = 5|
|%=||Modulus and assign||var a=10; a%=2; Now a = 0|
|(?:)||Conditional Operator returns value based on the condition. It is like if-else.|