I used to avoid reduce method in Javascript because of how confusing it was. Today I wrote my own reduce polyfill. Handling all edge cases, it was challenging at first but then it all clicks. While writing polyfills the core flow of callback, this context and iteration is the easiest & part. But in case of reduce you need to consider following : 1. Initial values 2. Sparse arrays (holes) 3. Dynamic start indexing 4. Edge case handling with custom errors Once you work on each pointers you will understand all edge cases, reduce is not just about iteration its about the flow. #javascript
My Reduce Polyfill for Javascript
More Relevant Posts
-
We analyzed a page with 22MB uncompressed size. 17MB of that? JavaScript. 140 JS requests. 19.1s JS execution time. 4.6s TBT 🧐 Too much JavaScript hurts performance and your visitors feel it. Learn how you can fix it: https://lnkd.in/eER3Y65P #webperformance #gtmetrix
To view or add a comment, sign in
-
-
Day 18 of My JavaScript Journey 🚀 Today, I built my second JavaScript project (A Modal Window.) The project works like this: • Clicking show modal button opens a modal (popup box) • Clicking the close button hides it • Pressing the “Escape” key also closes it In this project, I used: • document.querySelector to select elements • addEventListener to handle user actions • classList to show and hide the modal • keydown event to detect when the ESC key is pressed One thing I found interesting: Handling keyboard events made the project feel more interactive and user-friendly. Key takeaway: JavaScript allows you to control both mouse and keyboard interactions on a webpage. #JavaScript #WebDevelopment #LearningInPublic #100DaysOfCode
To view or add a comment, sign in
-
-
🧠 Day 3 of 21 days challenge JavaScript Event Loop 🤯 Event Loop is a mechanism in JavaScript that handles execution of asynchronous code. It continuously checks the call stack and callback queue. If the stack is empty, it moves tasks from the queue to the stack for execution. For example :- console.log("Start"); console.log("End"); console.log("Timeout"); Wait… why this order? Because JavaScript doesn’t run everything instantly. It uses: • Call Stack • Web APIs • Callback Queue Event Loop decides what runs next. 💤For easy understanding :- Event Loop = decides execution order Sync code runs first Async code waits in queue Then runs after the stack is empty 👉 That’s why “Timeout” runs last This changed how I understand async code 🚀 #JavaScript #EventLoop #Async
To view or add a comment, sign in
-
-
🚀 Day 14/30 of My JavaScript Challenge Solved LeetCode 2715 - Timeout Cancellation ✅ 💡 What I Learned Today: ⏳ How setTimeout() delays function execution ❌ How clearTimeout() cancels a scheduled task 🔁 Returning functions from functions (Higher-Order Functions) 🧠 Managing async behavior in JavaScript 📌 Approach: Created a cancellable function that schedules execution using setTimeout(). Then returned a cancelFn which uses clearTimeout() to stop execution before the delay ends. ✨ Key Insight: JavaScript timers can be controlled dynamically, which is useful in search debouncing, API calls, and UI interactions. #JavaScript #LeetCode #30DaysChallenge #WebDevelopment #AsyncJavaScript #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
#JourneyToTechJob – Day 8 🚀 #50DaysOfRevision Built a simple Traffic Light Simulator using JavaScript. Features: ✔️ Switch between Red, Yellow, and Green lights ✔️ Dynamic UI updates using DOM manipulation ✔️ Button-based interactions What I revised: → Event handling in JavaScript → DOM manipulation → Writing cleaner and reusable functions 🔗 Live Demo: https://lnkd.in/g-Qnknr4 Here's a quick demo of the project👇 #SoftwareDevelopment #JavaScript #FrontendDevelopment #WebDevelopment #HTML #CSS #Projects #BuildInPublic #Consistency #50DaysOfCodeChallenge
To view or add a comment, sign in
-
setTimeout does nothing inside the JavaScript engine. It's a label. A facade. When you call it, JS hands the work off to a browser feature - the actual timer lives outside JavaScript entirely. The browser runs it independently while JS continues on to the next line. All the features we think of as "JavaScript" - timers, network requests, DOM interactions - are actually browser APIs. JS just has labels that trigger them. This is how JS avoids blocking. It doesn't wait. It delegates. The result comes back later, through a controlled channel called the callback queue. Next: the event loop - the single mechanism that controls when deferred code is allowed back into JavaScript. #JavaScript #WebDevelopment #Programming #SoftwareEngineering
To view or add a comment, sign in
-
Today’s practice was all about understanding how DOM manipulation really works in JavaScript. I worked on deleting elements dynamically using event handling. At first, it looked simple — just use "remove()" and done. But while practicing, I discovered an important edge case. When using "event.target.parentNode.remove()", it works perfectly when clicking on the intended element (like an image inside a list). But if you click outside the expected target, it can remove the wrong parent — even the entire list. To fix this, I implemented a condition to ensure deletion only happens when the clicked element is the correct one ("IMG" tag). This small practice helped me understand: • The difference between "event.target" and "event.currentTarget" • How DOM structure affects behavior • Why adding conditions makes code safer Every small bug teaches something valuable. #JavaScript #DOM #FrontendDevelopment #LearningInPublic #WebDevelopment
To view or add a comment, sign in
-
-
🧠 Day 10 of 21days challenge JavaScript call, apply, bind 🔥 They allow you to control what “this” refers to in a function. You can borrow functions and use them with different objects. For easy understanding :- call → pass arguments one by one apply → pass arguments as array bind → returns new function 👉 That’s how we control “this” in JavaScript This changed how I understand functions 🚀 #JavaScript #CallApplyBind #Frontend
To view or add a comment, sign in
-
-
Day 16/100 of JavaScript Today’s topic : DOM Events After understanding DOM structure, the next step is handling user interactions using events JavaScript can listen to events and respond to user actions like clicks, typing, or scrolling 🔹Adding event listener const btn = document.getElementById("btn"); btn.addEventListener("click", () => { console.log("Button clicked"); }); 🔹Common events - click - input - submit - keydown 🔹Event object btn.addEventListener("click", (event) => { console.log(event.target); }); 🔹Event bubbling (basic idea) Events propagate from child → parent unless stopped event.stopPropagation(); DOM events allow JavaScript to make web pages interactive by responding to user actions #Day16 #JavaScript #100DaysOfCode
To view or add a comment, sign in
-
I've been writing JavaScript for over a year. Thought I understood var, let, and const. I didn't. "var a" inside a block accessible outside. Prints "10". "let b" inside the same block, try to access it outside and you get: ReferenceError: b is not defined Same block. Same code. Completely different behavior. Turns out var lives in global memory. let and const get their own separate block scope. Once the block is done, they're gone. This is why going back to fundamentals matters #JavaScript #WebDev #LearnInPublic #NamasteJavaScript
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