September 2015
Intermediate to advanced
92 pages
1h 30m
English
CHAPTER 6
![]()
Conditionals
Conditional statements are used to execute different code blocks based on different conditions.
If Statement
The if statement only executes if the expression inside the parentheses is evaluated to true. In JavaScript, this does not have to be a Boolean expression. It can be any expression, in which case zero, null, NaN, empty strings, and undefined variables are evaluated as false, and all other values are true.
if (x < 1) { document.write("x < 1");}
To test for other conditions, the if statement can be extended by any number of else if clauses. Each additional condition will only be tested if the preceding conditions ...
Read now
Unlock full access