Conditionals: Comparison operators

After the assignment and arithmetic operators, the third set of operators I want to introduce is comparison operators.

They are one of the most important operators category in JavaScript.

Comparison operators always returns a boolean, a value that’s true or false, and they are divided in 2 groups: equality operators , and disequality comparison operators.

These are equality operators:

  • === checks for equality
  • !== checks for inequality

These are disequality comparison operators:

  • < means “less than”
  • <= means “less than, or equal to”
  • > means “greater than”
  • >= means “greater than, or equal to”

You can use them to compare two numbers, or two strings.

Note that we also have == and != in JavaScript, but I highly suggest to only use === and !== because they can prevent some subtle problems.

Lessons in this unit:

0: Introduction
1: ▶︎ Comparison operators
2: `if` statements
3: How to use `else`
4: `switch`
5: The ternary operator
Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. Launching May 21, 2024. Join the waiting list!