Now that we've cemented our understanding of how control is moved at a high level, we can delve further into the specific statements and mechanisms that JavaScript gives us to control flow. We'll combine an exploration of the syntax of each statement with some best practices and pitfalls to avoid.
Statements of control flow
The if statement
The if statement is composed of the if keyword followed by a parenthesized expression and then an additional statement:
if (ConditionExpression) Statement
ConditionExpression can be of limitless complexity as long as it is truly an expression:
if (true) {}
if (1 || 2 || 3) {}
if ([1, 2, 3].filter(n => n > 2).length > 0) {}
The statement following the parenthesized expression...