JavaScript Conditionals
🧠 What Are Conditionals?
JavaScript conditionals allow the program to make decisions based on conditions.
They execute different code depending on whether something is true or false.
🔹 Types of Conditional Statements
-
if -
if...else -
else if -
switch
1️⃣ if Statement
Runs code only if the condition is true.
2️⃣ if…else Statement
Runs one block if true, another if false.
3️⃣ else if Statement
Used when there are multiple conditions.
4️⃣ switch Statement
Used when you want to compare the same variable with many values.
📌 Example in HTML with Output
Output (for temperature = 30):
🏁 Summary Table
| Conditional Type | When to Use |
|---|---|
if |
Single condition |
if...else |
Two possible outcomes |
else if |
Multiple conditions |
switch |
Many fixed value comparisons |
