4.3 - Comparison Operators
comparison operators
Comparison operators are used in logical statements to determine equality or difference between variables or values.
Given that x = 5
, the table below explains the comparison operators:
Operator | Description | Comparison |
---|---|---|
=== | equal to | x === 5 (true) |
!== | not equal | x !== 8 (true) |
> | greater than | x > 8 (false) |
< | less than | x < 8 (true) |
>= | greater than or equal to | x >= 8 (false) |
<= | less than or equal to | x <= 8 (true) |
triple equals sign
In JavaScript we use the triple equals sign (===) instead of double equals sign (==). This is called strict equality and is used for checking that both sides have the same type.
your turn: comparison operators task
We have these two variables:
let sweetCandy = 100;
let sourCandy = 150;
Find the answers to these questions using JavaScript comparison!
- Is the number of sweet candies greater than the number of sour candies?
- Is the number of sour candies less than or equal to the number of sour candies?