The basics of syntax

INPUT · Slides

true and false

01 / 05

Yes and no are values too

Just like text and numbers, true and false are values you can work with. true means "yes, it holds", false means "no, it does not".

Together they are called booleans. No quotes around them, so they are not the same as the string "true".

console.log(true);console.log(false);

Result

true
false

02 / 05

Comparing gives you a boolean

Write a comparison like 5 > 3 and it turns into true or false on the spot.

A sum turns into a number; a comparison turns into a boolean. Same idea.

console.log(5 > 3);console.log(2 > 8);

Result

true
false

03 / 05

Does exactly equal count

The only difference between > and >= is what happens when the two are the same. 10 > 10 does not hold; 10 >= 10 does.

Think about which you want at the boundary and pick accordingly.

console.log(10 >= 10);console.log(10 > 10);console.log(10 <= 9);

Result

true
false
false

04 / 05

A boolean can have a name

The result of a comparison is a value, so you can put it in a variable.

That variable then goes straight into an if. Naming the condition means you can see at a glance what is being judged.

const score = 72;const passed = score >= 60;console.log(passed);if (passed) {  console.log("pass");}

Result

true
pass

05 / 05

Variables can be compared as well

You are not limited to comparing numbers you typed in. Two variables can be compared, and so can two worked-out results.

So this is what was really going on inside the brackets of an if all along. Try showing one and see.

const mine = 18;const yours = 25;console.log(mine < yours);

Result

true