JAVASCRIPT CONTROL FLOW STATEMENTS
CONTROL FLOW STATEMENTS
- If Statement
- If Else Statement
- If Else if statement
- For Loop
- White loop
- Break and Continue
- Time out and intervel
- Exception Handling
IF STATEMENT
The if statement executes a block of code if the given condition is true.
Syntax:
if (condition) { } |
Example:
If age is more then 18 pop up dialogue box is open .
<html> <head> <title>if statement</title> </head> <body> <button onclick="ifstatement()">click me</button> <script> function ifstatement( ) { const age = 20; if (age > 18 ) { alert("age is more then 18 years old"); } <script> </body> </html> |
IF-ELSE STATEMENT:
The else statement executes a Block of codes when the given condition to if is true
Syntax
if (condition) { }else{ } |