course content

Course Content

Introduction to JavaScript


Now we will consider the most important field of application of boolean type.


Conditions in JavaScript provide flow control. The interpreter executes commands in order, but often programmers need to control the execution flow. In some situations, it is necessary to branch the program's behavior based on certain conditions.

There are two keywords that can help you: if and else


The if keyword takes a boolean literal and opens a code block that will be executed if the taken literal is true:

In the example above, you can see that the if operator executes code when the taken literal is true.

The syntax of the conditional operator is so simple: if keyword, literal in the parentheses () and a code block in the curly brackets {}.

The { symbol opens the code block, and the } symbol closes it.

The literal can be replaced by the expression:

You can see the 4 conditions in the example above where a = 935:

ConditionCondition resultCode has been executed?
a > 17trueYes
a > 235124falseNo
a > 0trueYes
a < 0falseNo

You are not limited to performing operations inside the code block:

Section 4.

Chapter 1