DEV Community

Gayathri.R
Gayathri.R

Posted on

I learned conditional statements in javascript

what is the conditional statement

Conditional statements in JavaScript are used to make decisions in your code based on whether a condition is true or false. They control the flow of the program — like a road sign that tells your code where to go next.
If
Runs a block of code only if the condition is true.
Example:
let no=0;
if(no%2)
{
console.log (even);
}
else
{
console.log(ood);
}
Nested if

let mark>=35;
let result;
if(mark>=35)
{
result="pass";
}
else
{
result="fail";
}
Nested if
A nested if statement is when you put one if statement inside another if statement. It allows you to check more than one condition in a structured way.
if(budget<=2500)
{
if(brand=="Samsung")
}
if(can=="64mp")
{
console.log("purchas");
}
}
else
if(brand=="oppo")
{
if(cam=="72mp")
}
}

Top comments (0)