🔥 Debouncing vs Throttling in JavaScript User events can fire hundreds of times per second. Examples: • Typing in a search bar • Scrolling • Window resizing If your search input calls an API on every keystroke, performance will suffer. That’s where Debouncing and Throttling help. 🟢 Debouncing Runs the function only after the user stops typing. Perfect for search inputs. function debounce(fn, delay){ let timer; return (...args)=>{ clearTimeout(timer); timer = setTimeout(()=>fn(...args), delay); }; } Example: Typing Angular → only 1 API request, not 7. 🔵 Throttling Runs a function once every X milliseconds, no matter how many times the event fires. Best for scroll or resize events. function throttle(fn, limit){ let waiting=false; return (...args)=>{ if(!waiting){ fn(...args); waiting=true; setTimeout(()=>waiting=false, limit); } }; } ⚡ Quick Rule ✔ Debounce → Final result matters (Search) ✔ Throttle → Continuous updates (Scroll) Small techniques like these can greatly improve frontend performance. Do you use debounce or throttle more in your projects? 👀 #JavaScript #Angular #Frontend #WebDevelopment #Performance
Debouncing vs Throttling in JavaScript: Improve Frontend Performance
More Relevant Posts
-
🚀 Higher-Order Functions in JavaScript — A Must-Know Concept! 💡 What is a Higher-Order Function? A function is called a Higher-Order Function if it: ✔️ Takes another function as an argument ✔️ Returns a function as its result 🔍 Simple Example: function greet(name) { return `Hello, ${name}`; } function processUserInput(callback) { const name = "Jake"; return callback(name); } console.log(processUserInput(greet)); 👉 Here, processUserInput is a Higher-Order Function because it accepts greet as a callback. ⚡ Why are Higher-Order Functions powerful? ✅ Code reusability ✅ Cleaner and more readable code ✅ Helps in functional programming ✅ Widely used in JavaScript methods like: array.map(), array.filter(), array.reduce() 🔥 Interview Twist: function multiplier(factor) { return function (number) { return number * factor; }; } const double = multiplier(2); console.log(double(5)); // ? 🧠 Output: 10 👉 Because multiplier returns another function — classic Higher-Order Function! 🔥 The Important Concept: Closure Even though multiplier execution is finished, the inner function still remembers factor. This is called a closure: "A function remembers variables from its outer scope even after that outer function has finished executing." #JavaScript #WebDevelopment #Frontend #CodingInterview #Developers
To view or add a comment, sign in
-
🤯 One of the most confusing concepts in JavaScript — 'this' keyword If you've worked with JavaScript, you’ve probably asked: 👉 “What exactly does ‘this’ refer to?” Here’s the simple rule: 👉 “this = Who called me?” Let’s understand with examples 👇 📌 1. Object Method const user = { name: "Vinay", greet() { console.log(this.name); } }; user.greet(); // Vinay 👉 Here, 'this' refers to the user object 📌 2. Normal Function function show() { console.log(this); } show(); // window (in browser) 👉 Here, 'this' refers to the global object 📌 3. Arrow Function const obj = { name: "Vinay", greet: () => { console.log(this.name); } }; obj.greet(); // undefined 👉 Arrow functions don’t have their own 'this' 👉 They inherit it from the parent scope 📌 4. Event Listener button.addEventListener("click", function () { console.log(this); }); 👉 Here, 'this' refers to the clicked element 💥 Final Tip: 👉 “'this' is not about where it’s written, it’s about how it’s called.” Master this concept, and your JavaScript skills will level up 🚀 #JavaScript #WebDevelopment #Coding #DeveloperLife #Frontend #Programming #JSConcepts
To view or add a comment, sign in
-
-
🚀 Debouncing vs Throttling in JavaScript When optimizing performance in JavaScript, especially for scroll, resize, or search input events, two important techniques are Debouncing and Throttling. Let’s understand the difference 👇 🔹 Debouncing Debouncing ensures that a function runs only after a certain delay once the user stops triggering the event. 📌 Example: Search input suggestions When a user types quickly, you don’t want to call the API for every keystroke. Instead, wait until the user stops typing for 300–500ms, then call the API. 👉 Result: Fewer API calls and better performance Simple Example: function debounce(fn, delay){ let timer; return function(...args){ clearTimeout(timer); timer = setTimeout(() => { fn.apply(this, args); }, delay); } } --- 🔹 Throttling Throttling ensures that a function executes only once in a fixed time interval, no matter how many times the event occurs. 📌 Example: Scroll event handling When a user scrolls, the event fires many times per second. Throttling ensures the function runs only once every X milliseconds. 👉 Result: Controlled execution frequency Simple Example: function throttle(fn, limit){ let flag = true; return function(...args){ if(!flag) return; flag = false; fn.apply(this, args); setTimeout(() => { flag = true; }, limit); } } --- ⚡ Key Difference Debounce → Executes after the event stops Throttle → Executes at regular intervals while the event continues 📊 Common Use Cases Debounce: • Search suggestions • Input validation • Auto-save Throttle: • Scroll tracking • Window resize • Infinite scroll --- 💡 Tip for Frontend Developers If you want to reduce unnecessary API calls → use Debounce If you want to limit execution frequency → use Throttle --- #JavaScript #FrontendDevelopment #WebDevelopment #ReactJS #Coding #SoftwareEngineering
To view or add a comment, sign in
-
-
I reckon there'll be more and more of these pure JS frameworks coming. JavaScript is back in the spotlight, baby. TypeScript's added complexity is a useless overhead for AI coding assistants. Just use the right tools for the job, do not over-engineer just KISS 😘
Another day, another new JavaScript framework. Except this time there's two! Gea.js and ArrowJS were both released recently. They share something in common — No signals, no hooks, no runes. Just JavaScript. 👉 Gea.js — geajs.com → Around 13kb → Stores are classes, components are classes, and computed values are getters. → Vite plugin analyzes your JSX at build time and generates surgical patches. No virtual DOM, no diffing. → Currently tops the js-framework-benchmark among compiled frameworks, beating Solid and Svelte. → Ships with accessible UI components, mobile-first views, routing, and HMR out of the box. 👉 ArrowJS — arrow-js.com → Under 5kb. → Tagged template literals, reactive proxies, and zero build step required. → Positions itself for the agentic era. The full documentation fits inside 5% of a 200k context window, and it ships with WASM sandboxes so AI agents can safely generate and execute UI code. Both are tiny. They just have different preference as to which type of plain JavaScript — Gea bets on classes and OOP, Arrow bets on functions and template literals. Check them out, or wait until Friday, there'll probably be three more new ones by then 😬 ——— ♻ Repost to help others discover 📕 Save the post so you don't miss it 💡 Follow me Yangshun Tay and my company GreatFrontEnd for more
To view or add a comment, sign in
-
-
Blog 04 of my JS Unlocked series is live! 🚀 Function Declaration vs Function Expression: What's the Difference? 👇 These two look almost the same — but one works before you define it and the other throws an error. That one difference has caused bugs in every developer's life at least once. In this one I cover: ✅ What functions are and why we need them ✅ Declaration vs Expression — side by side ✅ Hoisting explained simply (no jargon) ✅ When to use which in real projects ✅ Hands-on challenge — call both before defining and observe what happens Would love your feedback if you read it 🙏 🔗 https://lnkd.in/d9yFhfah Thanks to Hitesh Choudhary Sir, Piyush Garg #JavaScript #WebDevelopment #Hashnode #WebDevCohort2026 #LearningInPublic #Frontend #JS
To view or add a comment, sign in
-
What do you think will be the output of these expressions in javascript? {} + [] [] + {} {} + {} [] + [] At first glance, most developers assume JavaScript will treat these as normal object or array operations. But the real reason behind the output is type coercion and how JavaScript converts objects and arrays into primitive values when using the + operator. When the + operator is used with objects or arrays, JavaScript tries to convert them into primitive values (usually strings). An empty array [] becomes an empty string "" An object {} becomes "[object Object]" After this conversion, the + operator performs string concatenation. So the expressions effectively become: "[object Object]" + "" "" + "[object Object]" "[object Object]" + "[object Object]" "" + "" Understanding this behavior is important because JavaScript’s implicit type coercion can sometimes lead to unexpected results in real-world applications. A simple rule to remember: {} → "[object Object]" [] → "" Once you remember this conversion, these puzzles become much easier to reason about. For more insightful content checkout below: 🟦 𝑳𝒊𝒏𝒌𝒆𝒅𝑰𝒏 - https://lnkd.in/dwi3tV83 ⬛ 𝑮𝒊𝒕𝑯𝒖𝒃 - https://lnkd.in/dkW958Tj 🟥 𝒀𝒐𝒖𝑻𝒖𝒃𝒆 - https://lnkd.in/dDig2j75 or Priya Frontend Vlogz 🔷 𝐓𝐰𝐢𝐭𝐭𝐞𝐫 - https://lnkd.in/dyfEuJNt #frontend #javascript #react #reactjs #html #css #typescript #es6 #interviewquestions #interview #interviewpreparation
To view or add a comment, sign in
-
-
𝗧𝗵𝗲 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 𝘄𝗶𝘁𝗵 𝗧𝗮𝗶𝗹𝘄𝗶𝗻𝗱 𝗝𝗜𝗧 𝗮𝗻𝗱 𝗥𝘂𝗻𝘁𝗶𝗺𝗲 𝗧𝗵𝗲𝗺𝗲𝘀 (𝗮𝗻𝗱 𝘁𝗵𝗲 𝗮𝗽𝗽𝗿𝗼𝗮𝗰𝗵 𝗜 𝘂𝘀𝗲𝗱). While working on my own UI library built with Tailwind CSS and React (TypeScript), I had to deal with a well-known limitation of Tailwind’s JIT compiler. Tailwind’s 𝗝𝗜𝗧 𝗰𝗼𝗺𝗽𝗶𝗹𝗲𝗿 generates CSS by analyzing static class names during the build process. However, this presents a challenge when implementing dynamic themes that rely on runtime values. For instance, consider trying to apply a theme color sourced from a runtime object, like so: className={`bg-[${userThemeColor}]`} The problem? Since 𝗧𝗮𝗶𝗹𝘄𝗶𝗻𝗱 𝗰𝗮𝗻’𝘁 𝗱𝗲𝘁𝗲𝗰𝘁 𝘁𝗵𝗲 𝗲𝘃𝗲𝗻𝘁𝘂𝗮𝗹 𝘃𝗮𝗹𝘂𝗲 𝗱𝘂𝗿𝗶𝗻𝗴 𝗯𝘂𝗶𝗹𝗱 𝘁𝗶𝗺𝗲, it fails to produce the necessary CSS, rendering the class ineffective. To tackle this issue, I devised what I call a “CSS Variable Bridge.” Here’s how it works: 1️⃣ A ThemeProvider converts theme values into CSS variables at runtime. 2️⃣ Components reference those variables using Tailwind’s arbitrary value syntax. This strategy allows Tailwind to generate the CSS once, while the browser dynamically fills in the relevant values. By using this approach, we not only retain the power of Tailwind but also embrace the flexibility needed for dynamic theming. Excited to share more insights as I continue to develop this library! 💡 Fun fact: This approach is similar to how modern UI systems like shadcn/ui handle theming — using CSS variables to support dynamic themes while keeping the CSS static. #React #TypeScript #UIDevelopment #UIlibrary #frontend #UIEngineering #softwareEngineering #TailwindCSS #javascript
To view or add a comment, sign in
-
-
𝗧𝗵𝗲 𝗥𝗲𝗮𝗹 𝗥𝗲𝗮𝘀𝗼𝗻 𝗪𝗵𝘆 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗦𝗮𝘆𝘀 𝗔𝗿𝗿𝗮𝘆𝘀 𝗔𝗿𝗲 𝗢𝗯𝗷𝗲𝗰𝘁𝘀 You've seen this before: typeof [] returns "object". You think: that's an array, why does JavaScript say it's an object? In JavaScript, typeof returns one of these: -undefined- "boolean" - "number" -string- "bigint" - "symbol" -function- "object" Notice what's missing? There's no "array". That's not an accident. Arrays are not a separate type in JavaScript. When you write const arr = [], you're actually doing const arr = new Array(). Array is a constructor that creates an object. So, typeof [] returns "object", which is correct. Arrays behave differently because they're specialized objects with: - Numeric keys - A dynamic length property - Built-in methods like map, filter, reduce Why didn't JavaScript make typeof [] return "array"? Two reasons: - Historical design: JavaScript was created to be simple, with a few primitives and everything else as objects. - Backward compatibility: changing typeof [] to return "array" would break millions of websites. To check if something is an array, use Array.isArray([]). This returns true. Avoid using typeof arr === "array", it doesn't work. Remember: arrays are objects with special behavior. Use Array.isArray() to detect arrays. JavaScript prioritizes backward compatibility over perfection. Source: https://lnkd.in/gqv4EDnt
To view or add a comment, sign in
-
Recently I wrote an article explaining the idea of Javascript prototypes from the ground up ⬆️ , starting from something familiar: plain objects, and gradually building toward how Javascript actually constructs prototype chain. If you have ever tried explaining prototypes to someone or struggled with the mental model yourself, you might find this interesting. Read here: https://lnkd.in/gCYnRNmv 🙋🏻♂️ While working with Javascript developers, I've noticed that prototypes remain confusing for a long time 🕰️ Most people eventually learn that objects “inherit” from other objects, but the underlying intuition often stays fuzzy Terms like prototype, [[Prototype]], and the prototype chain get used interchangeably, which makes the mental model 🧠 even harder to build Over time, I realized the problem usually isn’t the concept itself — it’s how it’s introduced. 👨🏻💻 Its a good 4-5 min read !! #javascript #frontend #softwareengineering #webdevelopment #blog #prototype
To view or add a comment, sign in
-
You say you’re “comfortable with JavaScript”? Cool. Let’s test that. Answer these in the comments 👇 🧠 1. What will this output? Why? 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨([] + []); 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨([] + {}); 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨({} + []); Most developers get at least one wrong. ⚡ 2. Predict the output: 𝘧𝘶𝘯𝘤𝘵𝘪𝘰𝘯 𝘰𝘶𝘵𝘦𝘳() { 𝘭𝘦𝘵 𝘤𝘰𝘶𝘯𝘵 = 0; 𝘳𝘦𝘵𝘶𝘳𝘯 𝘧𝘶𝘯𝘤𝘵𝘪𝘰𝘯 𝘪𝘯𝘯𝘦𝘳() { 𝘤𝘰𝘶𝘯𝘵++; 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨(𝘤𝘰𝘶𝘯𝘵); }; } 𝘤𝘰𝘯𝘴𝘵 𝘧𝘯 = 𝘰𝘶𝘵𝘦𝘳(); 𝘧𝘯(); 𝘧𝘯(); 𝘧𝘯(); What concept is this testing? 🔥 3. What’s the difference between these two? 𝘖𝘣𝘫𝘦𝘤𝘵.𝘧𝘳𝘦𝘦𝘻𝘦(𝘰𝘣𝘫); 𝘖𝘣𝘫𝘦𝘤𝘵.𝘴𝘦𝘢𝘭(𝘰𝘣𝘫); When would you use one over the other in production? 🧩 4. True or False? 𝘵𝘺𝘱𝘦𝘰𝘧 𝘯𝘶𝘭𝘭 === "𝘰𝘣𝘫𝘦𝘤𝘵" 𝘐𝘧 𝘵𝘳𝘶𝘦 — 𝘦𝘹𝘱𝘭𝘢𝘪𝘯 𝘸𝘩𝘺. 𝘐𝘧 𝘧𝘢𝘭𝘴𝘦 — 𝘦𝘹𝘱𝘭𝘢𝘪𝘯 𝘸𝘩𝘺. 🚀 5. Async trap — what happens here? 𝘢𝘴𝘺𝘯𝘤 𝘧𝘶𝘯𝘤𝘵𝘪𝘰𝘯 𝘵𝘦𝘴𝘵() { 𝘳𝘦𝘵𝘶𝘳𝘯 42; } 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨(𝘵𝘦𝘴𝘵()); What exactly gets logged? If you can answer all 5 confidently, you’re not just “using” JavaScript. You understand it. Drop your answers below 👇 Let’s see who’s interview-ready. #javascript #frontenddeveloper #codinginterview #webdevelopment #softwareengineering #DAY73
To view or add a comment, sign in
More from this author
Explore related topics
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
Keep it up.