Control structures and statements are essential in order to control the flow of your programs. You can control to carry out different operation in different circumstances.
There are three forms of if statement in JavaScript.
1.if
Statement
2. if...else
statement
3. if...else if...
statement
The if statement allows JavaScript to make decisions and execute statements conditionally.
if ( < condition > ) { <sequence of statement > ; }
if...else
statementThe 'if...else
' statement allows JavaScript to execute statements in a more controlled way.
if(<condition>) { <sequence of statement 1>; } else { <sequence of statement 2>; }
if...else if...
statementIt is an advanced form of if…else that allows JavaScript to make a correct decision out of several conditions.
if(<condition 1>) { <sequence of statement 1>; } else if(<condition 2>) { <sequence of statement 2>; } else(<condition 3>) { <sequence of statement 3>; }