Learn JavaScript
Conditionals
11.2
Lesson

else statement

The else statement executes a block of code when the condition in the if statement is false. It is used along with the if statement.

In the example given below, the condition in the if statement evaluates to false. Therefore, the code inside the else block executes.

If you change the value of x to 8, the output changes to x is even.