JavaScript Comparison Operators

JavaScript Comparison Operators: As well as assigning values or performing maths calculations, operators can be used to compare the values of variables. Being able to compare values allows us to make our web pages more interactive.

Using comparison operators we can write code that does different things depending on the values of our variables. Here are some of the different comparison operators you can use:

JavaScript Comparison Operators

Operator: Meaning:
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to

These operators can be used in JavaScript statements to ask questions about our variables. Then we can write code that makes different things happen to depend on the answer to the question.

Instructions for our browser that use comparison operators are called if statements and else statements. These types of statements are called conditionals, because they depend on the value, or condition, of the variable.


Related Links:

Introduction to JavaScript Control Flow: if/else Statements

JavaScript Glossary – Comparison Operators

Online JavaScript Compiler. Code on the go.

Expressions and Operators – JavaScript – MDN

Connected through code, Choose Your Platform!

About the Author: Bernard Aybout

In the land of bytes and bits, a father of three sits, With a heart for tech and coding kits, in IT he never quits. At Magna's door, he took his stance, in Canada's wide expanse, At Karmax Heavy Stamping - Cosma's dance, he gave his career a chance. With a passion deep for teaching code, to the young minds he showed, The path where digital seeds are sowed, in critical thinking mode. But alas, not all was bright and fair, at Magna's lair, oh despair, Harassment, intimidation, a chilling air, made the workplace hard to bear. Management's maze and morale's dip, made our hero's spirit flip, In a demoralizing grip, his well-being began to slip. So he bid adieu to Magna's scene, from the division not so serene, Yet in tech, his interest keen, continues to inspire and convene.