🌐 Day 63/100 — Debouncing vs Throttling (Why Performance Matters)
Today I learned something that completely changed how I think about user interactions in JavaScript.
Sometimes our code works perfectly…
but the website still feels slow.
Why?
Because events like scroll, resize, typing, and mouse move can fire hundreds of times per second.
And if our function runs every single time → the browser struggles.
That’s where two powerful techniques come in:
🔹 Debouncing
The function runs only after the user stops doing something.
Example:
Search bar suggestions
→ Wait until the user stops typing, then call API.
Result: Less API calls. Faster UI. Happier server.
🔹 Throttling
The function runs at a fixed interval while the event keeps happening.
Example:
Scroll animations
→ Update position every 200ms instead of every pixel.
Result: Smooth performance.
💡 Big realization:
Good developers make code work.
Better developers make code efficient.
Performance is not about speed of your laptop —
it’s about respecting the browser.
Small concepts… huge impact.
Ever wondered how some functions "remember" values even after they finish running?
That’s a closure.
In simple words:
A function can carry its outer variables with it — like a backpack — wherever it goes.
Example:
function counter() {
let count = 0;
return function () {
count++;
console.log(count);
};
}
const increment = counter();
increment(); // 1
increment(); // 2
increment(); // 3
Even though counter() already executed…
count is still alive inside increment().
That’s closure memory.
💡 Why real websites use closures:
• Data privacy (hide variables from global scope)
• Event handlers remembering values
• Caching & performance optimization
• React hooks & state management
So closures aren’t just theory —
they power interactive UIs every day.
Today’s takeaway:
👉 Functions in JavaScript don’t just run… they remember.
#JavaScript #WebDevelopment #Frontend #100DaysOfCode #LearningInPublic
Well done anna👍😊