var x = 5; // assigning the value 5 to variable x
var y = 2; // assigning the value 2 to variable y
var z = x + y; // assigning the value 7 to variable z (x + y)
In the above example two operators are used. The (=) sign is called the assignment operator and it is used to assign values to a variable. The (+) sign is used to add two numbers as in the above example we are adding x and y. It is an arithmetic operator because it is used for an arithmetic operation.
|%||Modulus (Remainder) Operator|
|=||x = y||x = y (Assignment)|
|+=||x += y||x = x + y (Addition Assignment)|
|-=||x -= y||x = x – y (Subtraction Assignment)|
|*=||x *= y||x = x * y (Multiplication Assignment)|
|/=||x /= y||x = x / y (Division Assignment)|
|%=||x %= y||x = x % y (Modulus Assignment)|
The addition assignment operator += is used to add a value to a variable.
The subtraction assignment operator –= used to subtract a value from a variable.
The multiplication assignment operator *= is used to multiply a variable.
The division assignment operator /= is used to divide by a variable.
The modulus assignment operator %= assigns a remainder to a variable.
var txt1 = “HowTo”;
var txt2 = “Code”;
var txt3 = txt1 + ” ” + txt2;
The result of txt3 will be:
The += assignment operator can also be used to concatenate or add two strings:
txt1 += “a code academy”;
The result of txt1 will be:
|==||To check equal to|
|===||To check equal value and equal type|
|!=||To check not equal|
|!==||To check not equal value or not equal type|
|>||To check greater than|
|<||To check less than|
|>=||To check greater than or equal to|
|<=||To check less than or equal to|
|typeof||Returns the type of a variable|
|instanceof||Returns true if an object is an instance of an object type|
|&||AND||5 & 1||0101 & 0001||0001||1|
||||OR||5 | 1||0101 | 0001||0101||5|
|^||XOR||5 ^ 1||0101 ^ 0001||0100||4|
|<<||Zero fill left shift||5 << 1||0101 << 1||1010||10|
|>>||Signed right shift||5 >> 1||0101 >> 1||0010||2|
|>>>||Zero fill right shift||5 >>> 1||0101 >>> 1||0010||2|