🚀 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
Mastering JavaScript Loops: Types & Examples
More Relevant Posts
-
🚀 Day 12 of JavaScript: Mastering Object Creation Methods! Just wrapped up an insightful session on JavaScript Day 12, diving deep into the different ways to create objects in JavaScript! Understanding these methods is crucial for writing efficient and maintainable code. 🔹 Key Concepts Covered: 1. Object Literal Notation The simplest and most common way to create objects. Ideal for static, predefined data. Example: const user = { name: "John", age: 30 }; 2. Constructor Functions Blueprints for creating multiple similar objects. Uses the new keyword to instantiate objects. Example: javascriptDownloadCopy codefunction Person(name, age) { this.name = name; this.age = age; } const user1 = new Person("John", 30); 3. ES6 Classes Syntactic sugar over constructor functions. More readable and modern approach. Example: javascriptDownloadCopy codeclass Person { constructor(name, age) { this.name = name; this.age = age; } } const user1 = new Person("John", 30); 4. Object.create() Method Creates objects with a specified prototype. Useful for inheritance and setting up prototype chains. Example: javascriptDownloadCopy codeconst personPrototype = { greet() { console.log("Hello!"); } }; const user1 = Object.create(personPrototype); 5. Factory Functions Functions that return object instances. Flexible and doesn't require the new keyword. Example: javascriptDownloadCopy codefunction createPerson(name, age) { return { name, age }; } const user1 = createPerson("John", 30); 💡 Why This Matters: Choosing the right method depends on your use case: * Object Literal: Quick, one-off objects. * Constructor Functions: Multiple instances with shared properties. * ES6 Classes: Modern, readable, and scalable. * Object.create(): When you need specific prototype chains. * Factory Functions: Flexible and avoids new keyword pitfalls. 🎯 Next Steps: Which method do you prefer and why? Let’s discuss in the comments! Drop your questions or examples of when you’d use each method. #JavaScript #WebDevelopment #Coding #Programming #ObjectCreation #ES6 #DeveloperCommunity #LearnInPublic #CodeNewbie #TechEducation #Tapacadlive #Tapacademy
To view or add a comment, sign in
-
-
🚀 Day 15 of #100DaysOfCode Today was all about mastering two powerful JavaScript concepts that make code cleaner, smarter, and more expressive: 👉 Array Destructuring 👉 Spread Operator 💡 1. Array Destructuring No more messy indexing! You can unpack values from arrays in a clean way: const arr = [10, 20, 30]; const [a, b, c] = arr; console.log(a, b, c); // 10 20 30 You can even skip values or set defaults: const [x, , z = 50] = [5, 15]; console.log(x, z); // 5 50 ⚡ Cleaner code = better readability. 💡 2. Spread Operator (...) This tiny syntax unlocks big power 💥 👉 Copy arrays: const arr1 = [1, 2, 3]; const arr2 = [...arr1]; 👉 Merge arrays: const a = [1, 2]; const b = [3, 4]; const merged = [...a, ...b]; 👉 Add elements easily: const nums = [1, 2, 3]; const updated = [...nums, 4]; 🔥 No loops. No push chaos. Just elegance. ✨ Key Takeaway: Destructuring simplifies access. Spread operator simplifies manipulation. Together? They make your JavaScript feel like magic 🪄 📈 Consistency is the real superpower. Showing up every day. Learning every day. #JavaScript #WebDevelopment #CodingJourney #100DaysOfCode #LearnInPublic #Developers #LearningInPublic Sheryians Coding School Sheryians Coding School Community
To view or add a comment, sign in
-
-
🚀 Day 7/100 of #100DaysOfCode Today was all about strengthening JavaScript fundamentals — revisiting concepts that seem simple but are often misunderstood. 🔁 map() vs forEach() Both are used to iterate over arrays, but they serve different purposes: 👉 map() Returns a new array Used when you want to transform data Does not modify the original array Example: const doubled = arr.map(num => num * 2); 👉 forEach() Does not return anything (undefined) Used for executing side effects (logging, updating values, etc.) Often modifies existing data or performs actions Example: arr.forEach(num => console.log(num)); ⚔️ Key Difference: Use map() when you need a new transformed array Use forEach() when you just want to loop and perform actions ⚖️ == vs === (Equality in JS) 👉 == (Loose Equality) Compares values after type conversion Can lead to unexpected results Example: '5' == 5 // true 😬 👉 === (Strict Equality) Compares value AND type No type coercion → safer and predictable Example: '5' === 5 // false ✅ 💡 Takeaway: Small concepts like these make a big difference in writing clean, bug-free code. Mastering the basics is what separates good developers from great ones. 🔥 Consistency > Intensity On to Day 8! #JavaScript #WebDevelopment #CodingJourney #LearnInPublic #Developers #100DaysOfCode #SheryiansCodingSchool #Sheryians
To view or add a comment, sign in
-
-
📆#Day 72 — JavaScript Learning 🚀 Today I learned about one of the core concepts behind how JavaScript actually runs code — Execution Context. Every time JavaScript runs a program, it creates an execution environment called an Execution Context. 🔹 Types of Execution Context ✅ Global Execution Context Created when the program starts this refers to the global object ✅ Function Execution Context Created whenever a function is invoked 🔹 Two Phases of Execution 1️⃣ Memory Creation Phase Variables → stored as undefined Functions → stored completely 2️⃣ Code Execution Phase Code runs line by line Values get assigned var x = 10; function test() { var y = 20; console.log(x + y); } test(); JavaScript creates separate execution contexts to manage this flow. 📌 Key Learning: Understanding Execution Context explains: Hoisting Scope Call Stack behavior Today I realized JavaScript isn’t just syntax — it’s an execution system. #Day72 #JavaScript #ExecutionContext #WebDevelopment
To view or add a comment, sign in
-
-
Day 70 — JavaScript Learning 🚀 Today I revisited one of the most misunderstood topics in JavaScript — Hoisting. ❌ Myth: “JavaScript moves declarations to the top.” ✅ Reality: JavaScript doesn’t move your code. It creates memory for variables and functions during the creation phase. --- 🔹 Example 1 — var console.log(a); var a = 10; 👉 Output: undefined Why? During memory creation: a = undefined So it exists… but has no value yet. --- 🔹 Example 2 — let & const console.log(b); let b = 20; 👉 Output: ReferenceError This is because of the Temporal Dead Zone (TDZ). let and const are hoisted too — but they are not initialized. --- 🔹 Example 3 — Function Hoisting greet(); function greet() { console.log("Hello"); } 👉 Works perfectly. But: greet(); const greet = function() { console.log("Hello"); } 👉 Error ❌ Because function expressions follow variable rules. --- 📌 What I understood today: Hoisting is not about “moving code.” It’s about how JavaScript creates memory before execution. Understanding this removes so many beginner-level bugs. #Day70 #JavaScript #Hoisting #WebDevelopment #DeepLearning
To view or add a comment, sign in
-
-
Day 2 of my JavaScript learning journey. Everyone says: “Just use let and const, never var.” Today I finally understood why. Variables already managed to confuse me once. Here’s what I explored today. Variables in JavaScript: -Variables store data so we can use it later in our program. There are three ways to create them: 1️⃣ var The old way. It’s function-scoped and gets hoisted, which can sometimes cause confusing behavior. 2️⃣ let Modern and block-scoped. You can change the value later. let score = 10; score = 20; 3️⃣ const Also block-scoped, but the value cannot be reassigned. const name = "Shobhit"; One interesting thing I learned: Even if a variable is declared with const, objects inside it can still be modified. Another surprising discovery: typeof null returns "object". This is actually a long-standing JavaScript bug from the early days of the language. It stayed because changing it would break too many websites. My rule going forward: Use const by default. Use let when the value needs to change. Avoid var. Day 2 done. Slowly understanding how JavaScript actually works. What confused you the most when you first learned JavaScript? #JavaScript #LearningInPublic #WebDevelopment #100DaysOfCode #Frontend
To view or add a comment, sign in
-
-
🚀 Understanding How JavaScript Actually Runs Behind the Scenes Today in college, I learned something that completely changed how I look at JavaScript execution. We often write code like this: var x = 10, y = 20; function add(x, y) { var res = x + y; return res; } console.log(add(x, y)); But what actually happens inside the JavaScript Engine? Here’s the simplified breakdown: 🧠 Step 1: Creation Phase (Memory Phase) JS scans the entire code first Variables are allocated memory and initialized with undefined Functions are stored in memory with their complete body ⚙️ Step 2: Execution Phase (Code Phase) Code runs line by line Variables get actual values Function is invoked A new execution context is created The Call Stack manages everything Understanding: Execution Context Memory Creation Code Execution Call Stack …makes JavaScript feel much more logical instead of “magic”. The output is simple: 30 But the process behind it is powerful. 📚 Currently diving deeper into JavaScript fundamentals as part of my B.Tech journey. #JavaScript #WebDevelopment #Programming #LearningInPublic #ComputerScience #FrontendDevelopment
To view or add a comment, sign in
-
-
🚀 Day 36/50 – Understanding Functions in JavaScript Today I explored one of the most important concepts in JavaScript — Functions. 🔹 A function is a reusable block of code designed to perform a specific task. 🔹 Functions help make code modular, reusable, and easy to maintain. 📌 1️⃣ Function Declaration function greet(name) { return "Hello, " + name + "!"; } console.log(greet("Priyanka")); 2️⃣ Function Expression const add = function(a, b) { return a + b; }; console.log(add(5, 3)); 3️⃣ Arrow Function (ES6) const multiply = (a, b) => { return a * b; }; console.log(multiply(4, 2)); ✔ Shorter syntax ✔ Cleaner and more readable 4️⃣ Default Parameters function welcome(name = "Guest") { return "Welcome, " + name; } console.log(welcome()); 💡 Key Learnings: ✅ Functions improve code reusability ✅ Arrow functions make code concise ✅ Parameters and return values make functions dynamic ✅ Clean function design is important for scalable applications #Day36 #50DaysOfCode #JavaScript #WebDevelopment #FrontendDevelopment #CodingJourney #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 82 of My #100DaysOfCode Challenge Today I learned about a very useful JavaScript feature — Optional Chaining ("?."). When working with deeply nested objects, accessing properties can sometimes cause errors if a value is "undefined" or "null". Optional chaining helps solve this problem by allowing us to safely access nested properties without breaking the code. Example without Optional Chaining const user = { profile: { name: "Tejal" } }; console.log(user.profile.name); If "profile" doesn’t exist, this code would throw an error. Example with Optional Chaining const user = { profile: { name: "Tejal" } }; console.log(user?.profile?.name); Output Tejal If a property doesn't exist, JavaScript simply returns undefined instead of throwing an error. Why this is useful • Prevents runtime errors • Makes code cleaner and shorter • Helpful when working with APIs and complex objects Small modern features like this make JavaScript development much smoother. Continuing to explore deeper concepts and improving step by step. 💻✨ #Day82 #100DaysOfCode #JavaScript #OptionalChaining #WebDevelopment #LearningInPublic
To view or add a comment, sign in
-
-
🚨 JavaScript looks simple… until you start learning its quirks. Today I had a learning session on JS, and honestly, it reminded me why this language is both powerful and weird at the same time. Some things look obvious… until you realize JavaScript behaves differently than you expected. Here are a few insights that made me pause today 👇 🔹 Arrays can act like a deque Push, pop, shift, unshift -- both ends are usable. 🔹 Arrays compare by reference, not value Two identical arrays are still different objects. 🔹 sort() is tricky By default it sorts lexicographically, not numerically. 🔹 [Symbol.iterator] defines iterables If an object implements it, you can loop through it. 🔹 Array-likes exist Objects like String, arguments, and NodeList have indexes and length, but they are not real arrays. 🔹 Map vs Set Map → key/value with flexible keys Set → collection of unique values 🔹 WeakMap & WeakSet They store weak references, which helps JavaScript’s garbage collector automatically clean up unused objects 🤠 And of course… JavaScript Date -- the old sheriff in town. Every time I study JS deeper, I realize how many hidden behaviors it has. What’s the most confusing JavaScript concept you’ve learned recently? #JavaScript #WebDevelopment #CodingJourney #FrontendDevelopment #LearnInPublic
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development