DEV Community

Nandhini
Nandhini

Posted on

conditional statements in JS


Enter fullscreen mode Exit fullscreen mode

Conditional statements allows us to perform various different operations for different conditions. It run different code depending on true or false conditions.

It includes;

  • if statement

  • if.. else.. statement

  • if.. else if.. else.. statement

  • switch statement

  • ternary

If statement

"if" statement is used when specific code needs to executed if the given conditions is true.

Syntax:
if (condition == true){
/execute the block of code/
}
Enter fullscreen mode Exit fullscreen mode

If.. else.. statement

"If.. else" statement, if used when given condition is true and block is executed. And, else is used when given condition is false.

Syntax:
if (condition == true){
/execute the block of code if condition is true/
} else{
/execute the block of code if condition is false/
}
Enter fullscreen mode Exit fullscreen mode

similarly other statements also execute depending on true or false. In switch statement, it has multiple options...

Top comments (0)