Now we will study the special construct
if-else
, which allows some code
to be executed depending on some condition.
Using the construct if-else
, we can
ask the program, for example, the question
"is the variable a
greater than the
variable b
", and depending on the
answer, execute one code or another.
The construct syntax looks like this:
if (comparison operation) {
/*
the code written here will be executed if the
result of the comparison operation is true
*/
} else {
/*
the code located here will be executed if the
result of the comparison operation is incorrect
*/
}
There are many operators for comparison operations in JavaScript. Let's get started studying them.