Comparison Operators


Comparison operators are used to compare two values in JavaScript. They return a boolean result — either true or false.

These operators are mainly used inside conditional statements to make decisions. For example, checking if a number is greater than another number or if two values are equal.

Understanding comparison operators is very important because almost every condition depends on them.

Common Comparison Operators in JavaScript

==   checks if values are equal  
===  checks if values and types are equal  
!=   checks if values are not equal  
!==  checks if values or types are not equal  
>    greater than  
<    less than  
>=   greater than or equal to  
<=   less than or equal to  

These operators help programs compare data correctly.

This example compares two numbers using different operators. Each comparison returns either true or false.

This shows how comparison operators help programs make decisions.

The first comparison returns true because == checks only the value.

The second comparison returns false because === checks both value and data type.

Professional developers prefer === to avoid unexpected results.

This example shows how comparison operators are used in real-life conditions such as age verification and access control.

By mastering comparison operators, students gain strong control over conditional logic in JavaScript programs.