What is an if else statement in JavaScript?
If…else is a conditional statement that will execute block of code when the passed condition is truthy. When the condition is false, it will execute the else block . In if statement truthy and falsy values get converted in true and false.
Javascript else if
Many times when we write code, we want to check different conditions for different zzs. We can use conditional statements (Conditional statements are defined as performing different actions based on different conditions.) in our code to do this. In JavaScript we have the following conditional statements:
- if to specify a block of code to be executed, if a specified condition is evaluated to true.
- else to specify a block of code to be executed if the same condition is evaluated to false
- else if to specify a new condition to test, if the first condition is evaluated to false
- switch to specify many different blocks of code to be executed
SYNTAX –