Comparison Operators
There are 6 types of comparison operator.
Greater/less than(>/<)
Greater/less than or equal(>=/<=)
Equals(==)
Not equals(!=)
Strict equal(===)
Strict not equal(!==)
Greater/less than(>/<)
Greater/less than operator is used to compare the value whether it is greater or less based on that it return true or false
eg-
13>24
false
10<100
true
Greater/less than or equal(>=/<=)
The greater than oe equal to this is new operator that checks whether the value is greater than or equal to another value.
eg-
10>=12
false
10<=10
true
Equals(==)
This is for checking equality whether the value on the left hand side equal to on the right hand side or not.
- it is also known as Double equal
- In double equal implicit type conversion happen.
eg-
0 == 0
true
20 == 22
true
12=="12"
true(implicit type convesion happen)
Not equal(!=)
Not equal operator is compare the value and based on comparison gives the true or false.
eg-
21 != 21
false
"Hello" == "Hello"(because they are equal)
true
21 != 210
true
Strict Equal(===)
Strict equal only give true if the value of both right hand side and left side are of same type.
- it is also known as triple equal
- In triple equal explicit type conversion happen.
eg-
21 === "21"
false (false because the value of both right hand side
and left side are not in same type)
0 === 0
true
Strict Not Equal(!==)
Strict Not Equal only give true if the value of both right hand side and left side are not equal or not of same type.
eg-
2 !== "32"
true