If, Else If and Else Statements

Learn how to branch off based on conditional statements like if, else if and else statements.

The time has come when we can fit the puzzle pieces together. You have learned about different primitive and composite types. You know how to check these types. You know the basic functions and arithmetic (addition, subtraction, multiplication, etc.) and logical (true or false) operations in JavaScript.

There are only two things missing. So far, we can write a sequence of instructions that perform a calculation. In software development, there are three types of control structures:

  1. sequence: writing instructions one after the other
  2. selection: either execute one set of instructions, or another
  3. iteration: execute a set of instructions a finite or infinite number of times

As you already know how to sequence instructions one after the other, it is time to learn about selection and iteration. Let’s start with selection:

Get hands-on with 1400+ tech skills courses.