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