Account
Categories

If-else statement


To check the condition in JavaScript, if the criteria are met (true), the code inside the if braces will execute.

If the condition is not true (false), then the code inside the else braces will execute.

Now you will clearly understand the code logic with the help of the flowchart.

If-else Statement Flowchart:

First step: → You will write the program
                    |
Second step: → Now you will check the condition (yes/no)

If you find "Yes", then
                    |
              Execute Code

If you find "No", then
                    |
              Skip the Code

                    |
              End the program
Syntax:
if (condition) {
   // code runs if condition is true
} else {
   // code runs if condition is false
}
Example:
let number = 8;

if (number > 10) {
  console.log("Number is greater than 10");
} else {
  console.log("Number is 10 or less");
}
Output: