If a function fires 1000 times, but you only want it to run every 100 calls, there's a neat technique for that. Today I learned about counter-based sampling in JavaScript. Use Cases • sampling analytics events to reduce load • limiting noisy logs or metrics • running expensive work periodically in high-frequency flows How it's different from throttling? Sampling is call-count based → run every N calls Throttling is time-based → run at most once every X ms So if 1000 events fire instantly: • sampling (every 100) → runs 10 times • throttling (200ms) → may run only once Different problems, different tools. #javascript #softwareengineering #frontend #webdevelopment #todayilearned
Akash Sharma’s Post
More Relevant Posts
-
Filed an issue and shipped a fix to the official Module Federation Vite plugin this month. Most frontend teams on Vite still default to @originjs/vite-plugin-federation. Even tutorials published in late 2025 recommend it. That package hasn't shipped a release in over a year. The official one is @module-federation/vite. Vite 8 + Rolldown support landed this month. The issue tracker is active, and my PR got a real review within days. What surprised me digging in: - It orchestrates 15+ specialized internal Vite sub-plugins. Far more layered than I expected. - Manifest mode beats hardcoded entry URLs. Type sharing across remotes is automatic. - Runtime hooks make auth, routing, and A/B testing on remotes clean. - Migration off originjs is shorter than it looks. Most configs map over with light edits. The bug I fixed: a regex was matching Stencil's minified getScopeId, crashing every Stencil component at runtime. If your micro-frontend setup feels stuck in 2022, look again. PR + issue links in the comments. #ModuleFederation #Vite #MicroFrontends #OpenSource #Frontend #React #Javascript #Typescript
To view or add a comment, sign in
-
What To Know in JavaScript (2026 Edition). Part 2. New Set Methods (working with collections) JavaScript now includes new methods for Set, enabling operations like in math: intersection, union, difference. This turns Set into a truly powerful tool — not just a “unique array”. Now you get: - fewer utility functions - cleaner code - more declarative logic #frontend #webdev #javascript #performance
To view or add a comment, sign in
-
-
If a function fires 1000 times, but you only want it to run every 100 calls, there's a neat technique for that. Use Cases • sampling analytics events to reduce load • running expensive work periodically in high-frequency flows How it's different from throttling? Sampling is call-count based → run every N calls Throttling is time-based → run at most once every X ms So if 1000 events fire instantly: • sampling (every 100) → runs 10 times • throttling (200ms) → may run only once #javascript #frontend
To view or add a comment, sign in
-
-
🚀 #JavaScript Event Loop If you want to truly understand JavaScript async behavior, you must understand the Event Loop. 👉 What is Event Loop? It’s a mechanism that allows JavaScript to handle asynchronous operations using: • Call Stack • Web APIs • Task Queues (Microtask Queue & Macrotask Queue) 👉 Execution Flow: 1️⃣ Synchronous code runs first (Call Stack) 2️⃣ Then Microtasks execute → Promises, queueMicrotask 3️⃣ Then Macrotasks execute → setTimeout, setInterval ⚡ Rule: Microtasks always run before macrotasks. 💻 Example: console.log('Hi'); Promise.resolve().then(() => { console.log('Promise'); }); setTimeout(() => { console.log('Timeout'); }, 0); console.log('End'); ✅ Output: Hi End Promise Timeout 🧠 Why? Sync code runs first → Hi, End Promise goes to Microtask Queue → runs next setTimeout goes to Macrotask Queue → runs last #javascript #eventloop #promises #asyncjavascript #frontenddeveloper #webdevelopment #coding #100daysofcode #learnjavascript #developerlife #programming #jsdeveloper #tech #softwaredeveloper
To view or add a comment, sign in
-
-
What is the difference between shallow copy and deep copy? Copying objects in JavaScript is not always what it seems. A `shallow copy` duplicates only the first level. Nested objects are still shared by reference. A `deep copy` duplicates everything recursively. Why did this happen? - The top-level object was copied - But `address` still points to the same reference To fully isolate data, a deep copy is required. Understanding this is critical when: - Managing state - Avoiding unintended mutations - Debugging shared data issues The behaviour is subtle — but the impact is everywhere. #Frontend #JavaScript #WebDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
-
🧠 Day 18 of 21days challenge JavaScript WeakMap ⚡ WeakMap is a collection where keys must be objects. It helps in memory management because keys are weakly referenced. For easy understanding :- WeakMap = object keys only Garbage collected if no other references Useful to store private data 👉 That’s how memory leaks can be prevented This changed how I manage objects efficiently 🚀 #JavaScript #WeakMap #InterviewPrep #Frontend
To view or add a comment, sign in
-
-
I just published a new open-source library: input-mask. I built it because input masking on the frontend often feels more annoying than it should be, especially in simple projects, forms, landing pages, and workflows where you just want to configure the field and move on. The idea is straightforward: apply input masks using HTML attributes only, without needing to write JavaScript just to initialize everything. You add the library via CDN, use attributes like data-mask="pattern" or data-mask="currency" on the input, and it handles the rest. Under the hood it uses IMask, but the whole point was to hide that complexity and make the implementation much more accessible. The first public version already supports: • pattern • regex • number • currency • date Repo: https://lnkd.in/e6pkj7wB CDN: https://lnkd.in/ebc7fdr5 If anyone wants to try it, share feedback, or suggest improvements, I’d love to hear it. #javascript #frontend #webdev #opensource #forms #nocode
To view or add a comment, sign in
-
🧠 Day 4 of 21 days challenge JavaScript Hoisting 🤯 // var → undefined // let/const → error Why different behavior? Hoisting is a JavaScript behavior where variable and function declarations are moved to the top of their scope before execution. Only declarations are hoisted, not initializations. For easy understanding :- Hoisting = moving declarations to top var is hoisted with undefined let & const are hoisted but not initialized 👉 That’s why var gives undefined but let/const give error For example :- Normal code : console.log(score); // undefined var score = 90; JS will do this internally: var score; // first reserve console.log(score); // undefined score = 90; // then assign value This changed how I understand variable behavior 🚀 #JavaScript #Hoisting #Frontend
To view or add a comment, sign in
-
-
There's always something to gain from going back to the fundamentals. Between client projects and building out systems, I've been carving out time to sharpen my JavaScript. Recently covered: → Primitive vs Reference Data Types → Number, Null, Undefined, BigInt, and Symbols → The typeof operator → Ternary operators → Introduction to Object Destructuring None of this is glamorous. But the designers and developers who write clean, predictable code are almost always the ones who took the fundamentals seriously. Still a few more concepts on the list. Sharing the progress as I go. #JavaScript #WebDevelopment #Webflow #LearningInPublic
To view or add a comment, sign in
-
-
Ever wondered why this prints in a different order? console.log("Start"); setTimeout(() => { console.log("Timeout"); }, 0); console.log("End"); Output: Start End Timeout Wait… timeout is 0ms, right? So why does it run last? ⸻ 🧠 Welcome to the Event Loop JavaScript is single-threaded, but it handles async tasks using: 👉 Call Stack 👉 Web APIs 👉 Callback Queue 👉 Event Loop ⸻ ⚙️ What’s happening behind the scenes? 1️⃣ "Start" → goes to Call Stack → executed 2️⃣ setTimeout → sent to Web APIs 3️⃣ "End" → executed immediately 4️⃣ Callback enters queue 5️⃣ Event Loop pushes it back to stack 👉 That’s why "Timeout" runs last ⸻ 🔥 Key Insight: setTimeout(fn, 0) does NOT mean “run immediately” It means → “run after current execution is done” ⸻ 💬 Lesson learned: JavaScript isn’t just about syntax… It’s about understanding how it executes code ⸻ #JavaScript #WebDevelopment #Frontend #EventLoop #AsyncJavaScript #CodingJourney
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