30 Days Of JavaScript

Day 3: Logic

Lesson 1: If

We've seen the boolean true , false and the comparison operators < , === , !== , > but the real power of these doesn't kick in until the 'if' statement.

Try changing the happyCoder = true to happyCoder = false to see the not happy message print.

What's happening here is the === operator is testing what's on its left (happyCoder) and seeing if it is equal to what's on it's right (true) the result of that will be either true or false. Much like how the + operator adds what's on its left, to what's on it's right and tells us the total.

The if will run the code between it's { } if what's inside it's ( ) is true. If what's inside them is false, then the program skips to the next line after the { } brackets.

With that in mind go change the happyCoder === true to just true. And see how the message still prints. This is because all the 'if' statement cares about is the final result of whats in it's ( ).

Here's another example but this time using numbers.

Outline

Go Pro?

If you upgraded to pro, sign in here

  • About
  • Blog
  • Privacy
Looking to email me? You can get me on my first name at allthecode.co