Arithmetic operators are used to performing arithmetic operations between two variables or values. These are given below.
The two operands are compared with comparison operators. The comparison operators are as follows:
|==||Is equal to||20==30 = false|
|!=||Not equal to||20!=30 = true|
|===||Identical Equal to||5===2=false|
|!==||Idential Not Equal to||5 !== 2 = false
5 !== ”5″=true
|>||Greater than||10>20= false|
|<=||Less than equal to||10<=20=true
|=>||Greater than equal to||10>=20=false
The assignment operator (=) is used to assign a value to a variable. The assignment operators used in JS are given below.
|=||Assignment||a = b||a = b|
|+=||Addition Assignment||a += b||a = a + b|
|-=||Subtraction Assignment||a -= b||a = a - b|
|*=||Multiplication Assignment||a *= b||a = a * b|
|/=||Division Assignment||a /= b||a = a / b|
|%=||Modulus Assignment||a %= b||a = a % b|
|&=||Bitwise AND Assignment||a &= b||a = a & b|
||=||Bitwise OR Assignment||a |= b||a = a | b|
|^=||Bitwise Exclusive OR Assignment||a ^= b||a = a ^ b|
|<<=||Left Shift Assignment||a <<= b||a = a << b|
|>>=||Right Shift Assignment||a >>= b||a = a >> b|
The following logical operators are used to perform logical operations.
|&&||Logical AND||(20<30 && 30>20)=true|
|||||Logical OR||(10>30 || 30<40)=true|
The bitwise operator works on the basis of one bit, i.e. a binary number (0, 1). It calculates the given input by converting it into binary and returns the output again by converting it into a decimal number.
|<<||Bitwise Left Shift|
|>>||Bitwise Right Shift|
Sometimes we need to assign a value to a variable based on a condition. The conditional operator also called the ternary operator, by which we can perform this job easily.
Where do we put the question mark? And use a colon: We place a condition in square brackets () when this condition is true, then the first value returns from the colon, and when the condition is false, the value returns after a colon.
variable_name = (condition) ? value1:value2;
var a = 10; b = ( a == 10 ? 2 : 0 ); document.write("Value of b is "+b);