DEV Community

R.Shobika CSE
R.Shobika CSE

Posted on • Edited on

CONDITIONAL STATEMENT PART - 1

CONDITIONAL STATEMENT

In JavaScript Conditional statement is used to make a decision in program. It will execute the flow of program whether the condition is true means it return TRUE otherwise it return FALSE.

Conditional statement is work on comparison and logical operator

There are some types of Conditional Statements like [if, else if]

  1. IF- STATEMENT

In JavaScript, the if statement executes a block of code only if a specified condition evaluates to true. Use the else statement to specify a block of code to be executed if a condition is false.

let mark=32
if (mark>=35){
console.log("pass")
}else{
console.log("fail")
}
Enter fullscreen mode Exit fullscreen mode

output: fail

  1. ELSE IF - STATEMENT

In JavaScript the Else if condition is a new condition it execute when the first condition is false .

let mark =78
if(mark>=90){
console.log("A")
}
else if (mark>=75)
{
console.log("B")
}
else if (mark>=50){
console.log("C")
}
else{
console.log("fail")
}
Enter fullscreen mode Exit fullscreen mode

output : B

Top comments (0)