Comparison operators and syntax that can be used in javascript?
How to check not equal to, less and greater than condition of numerical values?
Explanation
Comparison Operators:
They are used to compare numerical (numbers), string or boolean values.
Operator-Syntax
Description
==
validates the condition whether two numbers or string values are equal
!=
validates the condition whether two numbers or string values are not equal
>
validates the condition whether one numbers is greater than other
<
validates the condition whether one numbers is less than other
>=
compares the numbers and checks whether one numbers is greater than or equal to other
<=
compares the numbers and checks whether one numbers is less than or equals other
===
used to compare and check whether two values are strictly equal
!==
used to compare and check whether two values are strictly not equal
The main difference between "equal to (==)" and "strictly equal to (===)" is that
the equality comparison takes place after type conversion for "equal to (==)" and before
type conversion for "strictly equal to (===)".
i.e "5" == 5 and "5" !== 5
Example Code:
<script language="javascript">
var a = "5";
var b = 5;
if(a == b)
{
document.write(" Testing Comparative Operator for equals ");
}
if(a === b)
{
document.write(" Testing Comparison Operator for strictly equals ");
}
</script>
Result:
As a is not strictly equal to b the second message is not printed.
A Note
Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script.
Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.