How to show if...else statement using a flowchart in JavaScript?

The if statement is the fundamental control statement that allows JavaScript to make decisions and execute statements conditionally. Let's see how to show if...else statement using flowchart in JavaScript.

If...Else Statement Flowchart

Start Condition? True False Execute if block Execute else block Next Statement End

Syntax

if (condition) {
    // Code to execute if condition is true
} else {
    // Code to execute if condition is false
}

Basic Example

let age = 18;

if (age >= 18) {
    console.log("You are eligible to vote");
} else {
    console.log("You are not eligible to vote");
}
You are eligible to vote

Multiple Conditions with else if

let score = 85;

if (score >= 90) {
    console.log("Grade: A");
} else if (score >= 80) {
    console.log("Grade: B");
} else if (score >= 70) {
    console.log("Grade: C");
} else {
    console.log("Grade: F");
}
Grade: B

Flowchart Explanation

The flowchart shows the logical flow of an if...else statement:

  • Start: Program execution begins
  • Condition: The boolean expression is evaluated
  • True path: If condition is true, execute the if block
  • False path: If condition is false, execute the else block
  • Merge: Both paths merge to continue with the next statement
  • End: Program execution continues

Practical Example with User Input

let temperature = 25;

if (temperature > 30) {
    console.log("It's hot outside");
} else {
    console.log("It's not too hot");
}

console.log("Weather check complete");
It's not too hot
Weather check complete

Conclusion

The if...else statement follows a clear decision-making flow as shown in the flowchart. It evaluates a condition and executes one of two code blocks, then continues with the rest of the program.

Updated on: 2026-03-15T22:04:42+05:30

359 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements