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

Uncovering Chennai: A Traveler and Local Perspective on City Life, Events and Landmarks

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

Modernizing Tech Stacks for Scalable Gaming Enterprises

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

Essential Qualities and Competencies to Look for in a DevOps Instructor

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

Exploring Your Backyard: Finding Local Goods, Shops, and Services

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 Your Way Through Oncology Care: A Patient and Family Roadmap

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 Excellence in Neurological Care: Selecting a Specialized Neurosurgery Facility

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
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x