Learn
Conditional Statements

# Comparison Operators

When writing conditional statements, sometimes we need to use different types of operators to compare values. These operators are called comparison operators.

Here is a list of some handy comparison operators and their syntax:

• Less than: `<`
• Greater than: `>`
• Less than or equal to: `<=`
• Greater than or equal to: `>=`
• Is equal to: `===`
• Is NOT equal to: `!==`

Comparison operators compare the value on the left with the value on the right. For instance:

``````10 < 12 // Evaluates to true
``````

It can be helpful to think of comparison statements as questions. When the answer is "yes", the statement evaluates to `true`, and when the answer is "no", the statement evaluates to `false`. The code above would be asking: is 10 less than 12? Yes! So `10 < 12` evaluates to `true`.

We can also use comparison operators on different data types like strings:

``````'apples' === 'oranges' // false
``````

In the example above, we're using the identity operator (`===`) to check if the string `'apples'` is the same as the string `'oranges'`. Since the two strings are not the same, the comparison statement evaluates to `false`.

All comparison statements evaluate to either `true` or `false` and are made up of:

• Two values that will be compared.
• An operator that separates the values and compares them accordingly (`>`, `<`, `<=`,`>=`,`===`).

Let's practice using these comparison operators!

Community Forums