JavaScript – Decision Making Statements

With decision-making statements in JavaScript, easily take decisions based on different conditions. The following are the decision-making statements in JavaScript:

  • if statement
  • if…else statement
  • if…elseif..else statement

if statement

The if statement in JavaScript executes the code if the condition is true. The following is the syntax of the if statement:

Let us see an example to implement the if statement in JavaScript:

Output

JavaScript if statement

if…else statement

The if…else statement in JavaScript executes some code if the condition is true and another code if
the condition is false. The false condition comes under else. The following is the syntax of the if…else statement:

Let us see an example to implement the if…else statement in JavaScript:

Output

JavaScript if...else statement

if…else if…else statement

The if…else if…else statement in JavaScript executes code for different conditions. If more than 2 conditions are true, you can use else for the false condition.

The following is the syntax of the if…else if…else statement:

Let us see an example to implement the if…else if…else statement in JavaScript:

Output

JavaScript if...elseif...else statement

JavaScript Tutorial
JavaScript Loops
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading