JS Tutorial



JS IF ELSE


JavaScript if else

The if statement is used to run code based on a condition. You can extend it using else if and else to handle multiple conditions.

๐Ÿ”น Example: Deciding what to wear based on temperature.

๐Ÿ“Œ Syntax

if (condition) {
  // code runs if condition is true
} else if (anotherCondition) {
  // code runs if anotherCondition is true
} else {
  // code runs if none are true
}

๐Ÿ” Real Example

let temp = 15;
if (temp > 30) {
  console.log("Wear a T-shirt");
} else if (temp > 20) {
  console.log("Wear a light jacket");
} else {
  console.log("Wear a coat");
}

๐Ÿงช Try It Yourself


Advice will appear here
๐Ÿ“˜ Summary:
Use if to check conditions, else if for more options, and else for fallback code. Perfect for decision making in your scripts!

๐ŸŒŸ Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review