
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What is if...else if... statement in JavaScript?
The if...else if... statement is an advanced form of if…else that allows JavaScript to make a correct decision out of several conditions.
Syntax
The syntax of an if-else-if statement is as follows −
if (expression 1){ Statement(s) to be executed if expression 1 is true } else if (expression2){ Statement(s) to be executed if expression 2 is true } else if (expression3){ Statement(s) to be executed if expression 3 is true } else{ Statement(s) to be executed if no expression is true }
Example
You can try to run the following to learn how to work with if…else if statement in JavaScript −
<html> <body> <script> var book= "maths"; if( book== "history" ){ document.write("<b>History Book</b>"); } else if(book == "maths" ){ document.write("<b>Maths Book</b>"); } else if(book == "economics" ){ document.write("<b>EconomicsBook</b>"); } else{ document.write("<b>Unknown Book</b>"); } </script> </body> <html>
- Related Articles
- What is the if...else statement in JavaScript?
- What is the ‘if...else if...else’ statement in Java and how to use it?
- Java if-else statement
- Java if-else-if ladder statement
- IF ELSE statement in a MySQL Statement?
- What is basic syntax of Python if...else statement?
- Java if-then-else statement
- What is the syntax of Python if...elif...else statement?
- Explain if-else statement in C language
- How to show if...else statement using a flowchart in JavaScript?
- What is if statement in JavaScript?
- Explain Nested if-else statement in C language
- Explain else-if ladder statement in C language
- What is the ‘if else’ statement in Java and how to use it?
- What is the resemblance of COALESCE() function with IF-THEN-ELSE statement?

Advertisements