Conditional Statements in JavaScript | Control Statement

A simple JavaScript program consists of a set of statements that generally contain expressions and end with a semicolon.

When we execute a JavaScript program, at a time, only one statement executes by JavaScript interpreter. These statements are called sequential statements.

Sequential statements are the statements that execute from top to bottom one by one. The flow of execution takes place from top to bottom in any program.

However, if we want to change the flow of a program, we can use flow control statements.

Flow control statements in JavaScript are those statements that change the flow of execution in a program according to requirements and needs of the user.

It provides better control to the programmer on the flow of execution in the program. These statements execute randomly and repeatedly. Control statements in JavaScript programming helps to write better and complex programs.

For example, a situation generally comes in the program, where we need to change the order of execution of statements based on specific condition or repeat a group of statements until particular specified condition meet.

In such situations, we can use the flow control statements or simply control statements in JavaScript program.

Types of Control Statements in JavaScript


JavaScript programming supports two kinds of control flow statements or decision-making statements.

  • Conditional statement
  • Unconditional statement

The further classification of control flow statements has shown in the below figure.

Types of control flow statements in JavaScript

Let us explore the two types of flow control statements in detail in the next section.

Conditional Statements in JavaScript


A conditional statement in JavaScript is that statement that breaks the sequential flow of a program and jumps to another part of the code based on a specific condition.

The flow of execution transfers from one part of code to another part on a specific condition. Therefore, it is also called conditional execution.

In JavaScript programs, we use conditional statements to perform different actions based on different conditions. JavaScript supports the four conditional control flow statements:

These conditional statements, known as selection statements in JavaScript because they execute a set of statements based on a condition.

The conditional statements use the boolean expression for conditional test. The boolean expression may be either a single expression or multiple expressions.

This boolean expression when evaluated generates a boolean value either TRUE or FALSE as a result. Based on the result, the boolean expression evaluates the statements on the basis of boolean values (true or false).

In other words, the result of conditional statements or decision statements determine the flow of execution in which a program will execute statements. Look at the below figure to understand more clearly.

Conditional statements in JavaScript

If there is only a single statement within the conditional statement, braces are optional. Braces are mandatory when there is more than one statement within a conditional statement or decision statement.

Unconditional Statements


An unconditional statement in JavaScript is that statement in which the flow of execution jumps to another part of code without carrying out any conditional test. It is also called unconditional execution in Java.

JavaScript supports three types of unconditional statements. They are as follows:

We will explore all the unconditional statement in detail in further tutorials.


In this tutorial, you have been familiar with the conditional and unconditional statements in JavaScript. Hope that you will have understood the all the basic points related to conditional statements.

In the next tutorial, we will learn if statement in JavaScript with various example programs.
Thanks for reading!!!
Next ⇒ If Statement in JavaScript⇐ PrevNext ⇒