Lesson 3 of 4 · 9 minutes

Comparing values

Conditions often compare values. Comparison operators ask questions: === means equal, > greater than, < less than, and >= or <= include equality.

Every comparison gives a boolean: true or false.

Be careful: a single = puts a value in a box. === checks whether two values are equal. Use === in a condition.

A balance scale represents comparisons while a separate arrow represents assignment

Comparison asks a question. Assignment fills a box.

Predict first: will each line print true or false?

Loading the editor…

Quick check

How do you check whether age equals 18?

Choose one answer.

What is the difference between = and ===?

Choose one answer.

You can now build conditions by comparing values — and you know why = and === must not be swapped.