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

  1. if

  2. if...else

  3. else if

  4. 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):

Weather is pleasant.

🏁 Summary Table

Conditional Type When to Use
if Single condition
if...else Two possible outcomes
else if Multiple conditions
switch Many fixed value comparisons

CodeCapsule

Sanjit Sinha — Web Developer | PHP • Laravel • CodeIgniter • MySQL • Bootstrap Founder, CodeCapsule — Student projects & practical coding guides. Email: info@codecapsule.in • Website: CodeCapsule.in

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *