Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views6 pages

Conditional Statement in Javascript

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Conditional Statement in Javascript

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Conditional

Statements
if-else statements

In computer programming, there may arise situations where you have to


run a block of code among more than one alternatives.

if (condition) {
// block of code if condition is true
} else {
// block of code if condition is false
}
if-else control flow
if-else-else-if-else control flow
nested if-else statements

You can also use an if...else statement inside of an if...else statement. This
is known as nested if...else statement.

if (condition1) {
if(condition2) {
} else {
}
} else {
// block of code if condition is false
}
Ternary Operator

A ternary operator evaluates a condition and executes a block of code based on the
condition.

condition ? expression1 : expression2

The ternary operator evaluates the test condition.


If the condition is true, expression1 is executed.
If the condition is false, expression2 is executed.

You might also like