Javascript If-Else.

  • Block of code of if-else statement gets executed when the specified condition is true.
  • And When the condition is false the else block will be executed.
Syntax
if (expression) {
   Statement(s) to be executed if expression is true
} else {
   Statement(s) to be executed if expression is false
}
    
Example
        let result;
        let age = 14;
        if (age > 18) {
            result = "You have right age now";
        } else {
            result = "You are under age";
        }

       Output :- "You have right age now"