Beginner
+25 XP

👋 Start learning JavaScript right now — for free!

📖

Comparison and Logical Operators

=== and !== for comparing values; && and || for combining conditions

⚖️

= and === — not the same thing

The most common beginner mistake: confusing = and ===. = (one equals sign) — ASSIGNMENT: put a value into a variable. === (three equals signs, read as 'strict equal') — COMPARISON: check whether two values are equal. The result of === is always true or false — nothing else.

Three = signs — not a typo

In JavaScript there are three equals and they're different:

  • = (one) — assignment: write a value into a variable
  • == (two) — loose equality: compares values but converts types
  • === (three) — strict equality: compares both value and type

Also two 'not equal':

  • != (one) — loose 'not equal', converts types
  • !== (two) — strict 'not equal', safe to use

Rule: always use === and !==. Never == and != — they give unexpected results.

All comparison operators

All return true or false:

OperatorReads asExampleResult
===strict equal5 === 5true
!==strict not equal5 !== 3true
>greater than10 > 3true
<less than2 < 1false
>=greater or equal5 >= 5true
<=less or equal4 <= 3false

Why === and not ==? See: "5" == 5 gives true — JS decided the string and number are the same. "5" === 5 gives false — correct, they're different types.

javascript
💬

=== checks both value and type — no surprises.

Logical operators

Allow combining multiple conditions:

OperatorMeaningExampleResult
&&AND — both conditionsage >= 18 && age < 65true
||OR — at least oneage < 18 || age > 65false
!NOT — inverts!truefalse

Rule &&: result is true only if BOTH conditions are true. Rule ||: result is true if at least ONE condition is true.

javascript
💬

Logical operators are the heart of any condition in code.

Remember the order: first ! (NOT), then && (AND), then || (OR). Like math: first multiplication, then addition. Parentheses always help make code clearer.

Comments

Log In or Start to leave a comment.