Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
if
course content

Course Content

Introduction to JavaScript

ifif

Conditions in JavaScript provide control over the execution flow. While the interpreter executes commands in order, programmers often need to alter this flow based on specific conditions. To achieve this, JavaScript offers two keywords: if and else.

if Statements

The if keyword allows you to open a code block that will be executed if the given condition is true:

In the above example, the if statement executes code only when the condition is true. The syntax of an if statement is straightforward: it begins with the if keyword, followed by the condition enclosed in parentheses (), and a code block enclosed in curly braces {}.

The opening curly brace { denotes the start of the code block, and the closing curly brace } marks its end.

An expression, as well as a value, can be considered as a condition.

In the example above, when a = 935, there are four conditions:

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

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

Everything was clear?

Section 4. Chapter 1
some-alt