From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Learn about if-statements in JavaScript

Learn about if-statements in JavaScript

- So now that we've gotten the subject of equality out of the way, let's take a look at one of the most common places where equality is used, and that's if statements. The basic syntax of if statements in JavaScript is, well, pretty boring. It's really similar to most other languages. The only thing that might be a little different is that in JavaScript, that condition has to be surrounded by parentheses. In other words, we can't leave the parentheses off like we can in languages such as Python. And of course we can add else if and else blocks to our if statement. Just like in other languages, the else if block will only be executed if none of the conditions in the blocks before it are truthy and its own condition is truthy, whereas the else block will only be executed if none of the other conditions in the other blocks are truthy. Okay, so you may be wondering why I am using the words truthy and falsey instead of just true and false. Maybe you remember that earlier in the course when…

Contents