Mastering JavaScript Loops: Types & Examples

🚀 Day 35/50 – Mastering Loops in JavaScript Today I strengthened my understanding of Loops in JavaScript — one of the most important concepts for writing efficient and dynamic code. 🔁 What is a Loop? A loop is used to execute a block of code repeatedly until a condition is satisfied. 📌 Types of Loops in JavaScript: 1️⃣ for loop – Used when the number of iterations is known. for(let i = 1; i <= 5; i++){ console.log(i); } 2️⃣ while loop – Executes while the condition is true. let i = 1; while(i <= 5){ console.log(i); i++; } 3️⃣ do...while loop – Executes at least once before checking condition. let i = 1; do{ console.log(i); i++; }while(i <= 5); 4️⃣ for...of loop – Used for iterating over arrays. let arr = [10,20,30]; for(let value of arr){ console.log(value); } 5️⃣ for...in loop – Used for iterating over object properties. let obj = {name:"Priyanka", role:"Developer"}; for(let key in obj){ console.log(key, obj[key]); } 💡 Key Learnings: ✔ Loops help reduce code repetition ✔ Choosing the right loop improves performance & readability ✔ Understanding break and continue statements is essential Thanks for mentors 10000 Coders Raviteja T Mohammed Abdul Rahman #Day35 #50DaysOfCode #JavaScript #WebDevelopment #FrontendDeveloper #CodingJourney #LearningEveryday

  • text

To view or add a comment, sign in

Explore content categories