- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the if...else statement in JavaScript?
The 'if...else' statement is the next form of control statement that allows JavaScript to execute statements in a more controlled way.
Syntax
Here’s the syntax −
if (expression) { Statement(s) to be executed if expression is true } else { Statement(s) to be executed if expression is false }
Here JavaScript expression is evaluated. If the resulting value is true, the given statement(s) in the ‘if’ block, is executed. If the expression is false, then the given statement(s) in the else block is executed.
Example
You can try to run the following to learn how to work with the if…else statement in JavaScript
<html> <body> <script> var age = 10; if( age > 18 ) { document.write("Eligible to vote!"); } else { document.write("<b>Not eligible to vote!"); } //--> </script> </body> </html>
- Related Articles
- What is if...else if... statement in JavaScript?
- What is the ‘if...else if...else’ statement in Java and how to use it?
- What is the syntax of Python if...elif...else statement?
- What is basic syntax of Python if...else statement?
- IF ELSE statement in a MySQL Statement?
- Java if-else statement
- Java if-else-if ladder statement
- What is the ‘if else’ statement in Java and how to use it?
- Java if-then-else statement
- What is the resemblance of COALESCE() function with IF-THEN-ELSE statement?
- How to show if...else statement using a flowchart in JavaScript?
- Explain if-else statement in C language
- What is if statement in JavaScript?
- Explain Nested if-else statement in C language
- Explain else-if ladder statement in C language

Advertisements