Conditional Statements
The following conditional statements are available in JavaScript:
- If a specified condition is true, use if to specify a block of code to be executed.
- If the same condition is false, use else to specify a block of code to be executed.
- If the first condition is false, use else if to specify a new condition to test.
- Switch is used to specify a large number of alternative code blocks to be executed.
The If Statement
Syntax
if (condition>
{
// block of code to be executed if the condition is true
}
Output:

Try it here