Javascript Comparison Operators |
The comparison operators are used in Javascript to compare values of variables. That means to check if two variables are equal, greater or less than other and some other functions.
List of Comparison Operators
| Operator | Operator name | Examples |
| == | Equal (note single = sign is used for assignment, not for comparison) |
|
| != | Not equal to |
|
| === | Strict Equal to (not only should match value but also variable type) | x = 50;
|
| < | Less than |
|
| > | Greater than |
|
| <= | Less than or equal to |
|
| >= | Greater than or equal to |
|
Examples of How Comparison operators are practically used.
In the example below, we will enter marks obtained by multiplestudents in the final exams (out of 1000 total marks) and at the backend, javascript code will compare the marks and list the highest marks(largest number) obtained along with the name of the student.
Dont worry now about how the code is working, we will look at that in the later lessons once we get familiar with more basic code writing. If you however wish to see the explanation for the code used in the above example, click here. (expand)