What are conditional statement in javascript?

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOps School!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

There are multiple different types of conditionals statement

  • “if” statement
  • “if else ” statement
  • “if else if” statement

“if” statement

The if statement is the fundamental control statement that allows JavaScript to make decisions and execute statements conditionally.

synatx

if (expression)
 {
   Statement
}

“if else” statement

The ‘if…else’ statement is the next form of control statement that allows JavaScript to execute statements in a more controlled way.

syntax

if (expression) 
{
   Statement
} else 
{
   Statement
}

“if else if “statement

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

if (expression 1) 
{
   Statement
} else if (expression 2) 
{
   Statement
} else if (expression 3) 
{
   Statement
} else 
{
   Statement
}

example

<!DOCTYPE html>
<html>
<head>
<title>javascript</title>
</head>
<body>
<script>
		var a=200;
		var b=300;
		
		if(a<b)
		{
		document.write("a is less than b");
		}
		else if(a>b)
		{
		document.write("a is greater than b");
		}
		else if(a==b)
		{
		document.write("a is equal to  b");
		}
		else
		{
		document.write("wrong value");
		}
</script>
</body>
</html>

output

a is less than b

Related Posts

Modernizing Software Delivery in the Dutch Tech Landscape: A Pragmatic DevOps Playbook

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

Finding Qualified AWS DevOps Trainers: Enterprise Playbook

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

Teaching Failure: How to Build Incident Response and Resilience into DevOps Training

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

The Open Road in Japan: An Independent Rider’s Handbook for Cross-Country Touring

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

A Comprehensive Guide to Scooters, Motorcycles, and Road Trips

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

Monitoring and Observability Training: Complete Curriculum Guide

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More
guest

0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x