JavaScript Decision Making and Semicolons Explained

Day 2 of My JavaScript Learning Journey Today I explored some fundamental concepts that helped me understand how decision-making works in JavaScript and how code execution actually flows. Understanding if vs if-else - "if" always checks its condition independently. - Multiple "if" statements will all run if their conditions are true. - "else" does NOT take a condition — it only runs when the previous "if" is false. Example insight: If we write multiple "if" statements like this: let marks = 85; if(marks > 90){  console.log("O"); } if(marks > 80){  console.log("A"); } if(marks > 60){  console.log("C"); } else {  console.log("FAIL"); } Output: A C Why? Because each "if" runs separately and checks its own condition. --- Important Learning If you want ONLY one condition to run, use: if...else if...else Otherwise, multiple outputs will come. --- Semicolon in JavaScript - Semicolon (";") is optional in many cases. - JavaScript automatically inserts it (ASI – Automatic Semicolon Insertion). But: - It becomes important when writing multiple statements in one line. Example: console.log("2"); console.log("nifty"); #JavaScript #WebDevelopment #CodingJourney #LearningInPublic #Day2

To view or add a comment, sign in

Explore content categories