If ... else command in JavaScript
While writing a program, there may be a situation when you need to follow one of a set of choices. In this case, you need to use conditional commands that allow your program to control the flow correctly and perform the right actions.
While writing a program, there may be a situation when you need to follow one of a set of choices. In this case, you need to use conditional commands that allow your program to control the flow correctly and perform the right actions.
JavaScript supports conditional commands used to perform various actions on the basis of different conditions. Below we will explain the if . else command.
The diagram performs the if . else command
The diagram below shows the if . else command to work:
JavaScript supports the following if.else order forms:
- If statement
- If . else statement
- If . else if . command
If statement
The if statement is a basic control command that allows JavaScript to control the flow and execute commands according to conditions.
Syntax
The syntax for a basic if statement is:
if ( expression ){ Statement ( s ) to be executed if expression is true }
Here, a JavaScript expression is evaluated. If the result is true, the provided command is executed. If the expression is false, no command will be executed. Most of the time, you will use comparison operators while controlling flow.
For example
Try the following example to understand how to work if :
- How to Print Double Quotes in Java
- How to Create an Executable File from Eclipse
- How to Enable Webgl
- How to Create a Javascript Console in Sublime Text
- How to Close a Window in Java
- How to Print an Array in Java
- Introduction to 2D Array - 2-dimensional array in JavaScript
- How to Run Program C/C++ Program in Netbeans
- How to Enable JavaScript in Mozilla Firefox
- How to Check Null in Java
How to save frequently used formulas on MathType