STATEMENTS
ECMA-262 describes several statements (also called flow-control statements). Essentially, statements define most of the syntax of ECMAScript and typically use one or more keywords to accomplish a given task. Statements can be simple, such as telling a function to exit, or complicated, such as specifying a number of commands to be executed repeatedly.
The if Statement
One of the most frequently used statements in most programming languages is the if
statement. The if
statement has the following syntax:
if (condition) statement1 else statement2
The condition can be any expression; it doesn't even have to evaluate to an actual Boolean value. ECMAScript automatically converts the result of the expression into a Boolean by calling the Boolean()
casting function on it. If the condition evaluates to true
, statement1 is executed; if the condition evaluates to false
, statement2 is executed. Each of the statements can be either a single line or a code block (a group of code...