When working with arrays in JavaScript, these four methods come up all the time forEach, map, filter, and find. They look similar, but each has a very specific purpose 1. forEach() Used when you want to loop through an array and perform an action (like logging, updating UI). it does not return a new array. 2. map() Used when you want to transform data. Returns a new array with modified values. Perfect for formatting API data. 3. filter() Used when you want to select specific items based on a condition. Returns a new array with matched elements only. 4. find() Used when you want to get a single item that matches a condition. Returns the first matched element, not an array. #JavaScript #ES6 #WebDevelopment #FrontendDeveloper #ReactJS #LearningInPublic
JavaScript Array Methods: forEach, map, filter, find
More Relevant Posts
-
⚡ JavaScript Concept: Event Loop — How JS Handles Async Code JavaScript is single-threaded… yet it handles thousands of async operations smoothly. How? 🤔 👉 The answer is the Event Loop 🔹 Execution Order 1️⃣ Call Stack — runs synchronous code 2️⃣ Web APIs — handles async tasks (setTimeout, fetch, etc.) 3️⃣ Callback Queue — stores completed async callbacks 4️⃣ Event Loop — moves callbacks to the stack 🔹 Example console.log("Start"); setTimeout(() => { console.log("Async Task"); }, 0); console.log("End"); 📌 Output: Start End Async Task 💡 Even with 0ms delay, async code runs after synchronous code. Mastering the Event Loop = mastering async JavaScript 🚀 #JavaScript #EventLoop #AsyncJS #Frontend #WebDevelopment
To view or add a comment, sign in
-
Day 3/30 JavaScript Challenge: Giving the Browser a Voice! 🗣️ I just finished Day 3 of my 30-day JavaScript series, and today was all about the Web Speech API. I built a Text-to-Voice application that turns any typed input into spoken words instantly! It’s amazing how much functionality is built right into the browser without needing any external libraries or APIs. Key Learnings Today: => Using SpeechSynthesisUtterance to handle voice properties. => Manipulating the DOM to capture user input. => Creating a clean, responsive UI with CSS gradients and transitions. Live Demo: https://lnkd.in/decEYAvw Onward to Day 4! ⚡ #JavaScript #WebDevelopment #CodingChallenge #100DaysOfCode #Frontend #LearningToCode
To view or add a comment, sign in
-
Ever wondered how JavaScript remembers variables even after a function has finished execution? It's The magic of Closure. A closure gives a function access to its outer scope. In JavaScript, closures are created every time a function is created, at function creation time. Example: function outer() { let count = 0; return function inner() { count++; console.log(count); }; } const counter = outer(); counter(); Result => 1 counter(); Result => 2 counter(); Result => 3 Explanation: Inner function remembers count from outer. Every time you call counter(), it retains the previous value. Usefulness of Closure: => Data encapsulation (private variables) => Memoization / caching => Event handlers & async callbacks Do you use closures in your projects? Share your use case below! #JavaScript #WebDevelopment #Closures #ReactJS #NexjJS #MERNStack #CodingTips
To view or add a comment, sign in
-
-
#Day 58/100 – Why JavaScript is Single-Threaded (and why that’s actually powerful) ⚡ When I first heard “JavaScript is single-threaded” I thought… Wait — only one thing at a time? Isn’t that slow? But today I understood something important. JavaScript being single-threaded is not a weakness. It’s the reason the web feels smooth. Imagine editing a form and suddenly the page freezes because 5 things run at once. That would be chaos. Instead, JavaScript follows a rule: Do one thing clearly, finish it, then move to the next. This makes UI predictable and prevents race conditions. But then how do videos load, APIs fetch data, and timers run? Because the browser handles heavy work in the background and JavaScript handles the result when it’s ready. So JS stays simple. The browser stays powerful. Big realization 💡 JavaScript isn’t trying to do everything at once — it’s trying to do everything in order. And that’s why websites don’t constantly break. Today I stopped thinking “single-threaded = limitation” Now I see “single-threaded = stability” #100DaysOfCode #JavaScript #WebDevelopment #LearningInPublic #FrontendDevelopment #CodingJourney
To view or add a comment, sign in
-
-
The JavaScript "this" Trap 🪤🔥 The Puzzle: What is the output? 🤔 const obj = { name: "JS", getName() { console.log(this.name); } }; const fn = obj.getName; fn(); Output: undefined Why? 🧠 In JavaScript, this depends on HOW a function is called, not where it is written. Lost Context: const fn = obj.getName only copies the function reference. Standalone Call: When you call fn(), there is no object (no dot) before the function. Global Context: It now runs in the Global Context (window object). Since window.name is not "JS", it returns undefined. How to Fix? 🛠️ ✅ Use .bind(): const fn = obj.getName.bind(obj); ✅ Use .call(): fn.call(obj); ✅ Use Arrow Functions: They inherit this from the surrounding scope. Interview Tip: 💡 Always check the "Call Site." No dot before the function call (like fn()) usually means this is lost! #JavaScript #CodingTips #365DaysOfCode #InterviewPrep #WebDev #FullStack #mern #react #node
To view or add a comment, sign in
-
⏳ “JavaScript is single-threaded.” I used to hear this everywhere. But then I had one question: If JavaScript is single-threaded… How does async code work? That’s when I learned about the Event Loop. Here’s the simple idea 👇 🧠 JavaScript has: • Call Stack • Web APIs • Callback Queue • Event Loop When async code runs (like setTimeout or fetch): 1️⃣ It moves to Web APIs 2️⃣ Once completed, it goes to the Callback Queue 3️⃣ The Event Loop checks if the call stack is empty 4️⃣ Then pushes it back to execute That’s why: console.log(1) setTimeout(() => console.log(2), 0) console.log(3) Output is: 1 3 2 Understanding this made debugging async bugs much easier. Frameworks don’t hide this. They rely on it. #JavaScript #EventLoop #WebDevelopment #FrontendDeveloper #NodeJS #SheryiansCodingSchool
To view or add a comment, sign in
-
-
🚀 Starting From Basics Again Before jumping into frameworks like React, I decided to strengthen my core , So I started revising HTML, CSS & JavaScript from scratch. Today, I built a simple Snake Game using pure HTML, CSS, and JavaScript , no libraries, no frameworks. While building this, I focused on: Proper HTML structure Clean and reusable CSS DOM manipulation Game logic implementation High score storage using localStorage What I learned from this: ✔ Fundamentals matter more than frameworks ✔ Logic building is more important than styling ✔ Clean and structured code makes debugging easier ✔ JavaScript feels powerful when you truly understand the DOM Deployed it using GitHub Pages 🔗 Live Demo: https://lnkd.in/dgCyVb4r 💻 GitHub Repository: https://lnkd.in/d3AtuqtF This is just the beginning. Next Moving towards React ⚛️ #WebDevelopment #JavaScript #HTML #CSS #React #LearningInPublic
To view or add a comment, sign in
-
-
Most people think functions "forget" everything once they finish running. Closures change the rules! While revising JavaScript fundamentals today, closures finally made sense to me. Normally, variables are garbage collected after execution. But closures allow inner functions to access outer variables even after the outer function has finished. In simple words, the inner function “remembers” its outer scope. 💬 Why this matters: • Private Variables : Closures let us protect data by keeping variables inaccessible from outside. • Persistent State : They allow functions to remember values without relying on global variables. • Event Handlers : They help UI elements remember what action to perform later. • Modules : They help organize code and prevent naming conflicts in larger applications. What’s one JavaScript concept that recently clicked for you? 👇 #JavaScript #WebDevelopment #Closures #LearningJourney
To view or add a comment, sign in
-
-
🚀 JavaScript Tip: Use find() Instead of filter()[0] I still see developers writing this: const user = users.filter(u => u.id === 1)[0]; But if you only need one item, find() is the better choice: const user = users.find(u => u.id === 1); Why? • filter() returns an array • It loops through the entire array • You only need one element find(): ✔ Returns the first match ✔ Stops iterating once found ✔ Improves readability ✔ More intention-revealing Small improvements like this make your code cleaner and more professional. What other JavaScript best practices do you follow daily? #JavaScript #WebDevelopment #Frontend #CodingTips #SoftwareEngineering
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