Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

OperatorDescriptionComparison
===equal tox === 5 (true)
!==not equalx !== 8 (true)
>greater thanx > 8 (false)
<less thanx < 8 (true)
>=greater than or equal tox >= 8 (false)
<=less than or equal tox <= 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!

  1. Is the number of sweet candies greater than the number of sour candies?
  2. Is the number of sour candies less than or equal to the number of sour candies?