𝗜 thought debounce and throttle were timing tricks. Turns out they’re memory problems. This week I explored debounce and throttle, and both are really about the same idea: 👉 controlling time by remembering state Debounce waits until events stop, then runs once Throttle runs at a fixed rate, no matter how noisy the events are Under the hood, it’s all about closures: storing timers remembering the last call deciding when a function is allowed to run I implemented both in vanilla JavaScript and then again in React using hooks (useRef, useEffect) to see how memory behaves across renders. Turns out: Performance isn’t about doing more — it’s about doing things at the right time. Still learning, but this clicked for me 💡 Would love to hear how others explain debounce vs throttle. #JavaScript #React #WebPerformance #LearningInPublic #Closures
Debounce vs Throttle: Controlling Time with Memory
More Relevant Posts
-
🌙 Evening Post — Function Reference vs Function Call (Very Important!) This morning’s code was: function show() { return "Hello"; } console.log(show); console.log(show()); 💡 Correct Output : [ Function : show ] Hello (Exact formatting may vary by browser, but the meaning is the same.) 🧠 Simple Explanation : 🔹 Line 1: console.log(show); Here, we are NOT calling the function. show refers to the function itself JavaScript prints the function definition This is called a function reference So the output shows something like: [ Function : show ] 👉 You’re telling JS: “Show me the function, not run it.” 🔹 Line 2: console.log(show()); Now the function IS called. show(); // returns "Hello" So this becomes: console.log("Hello"); ✔ Output: Hello 🎯 Key Takeaways : show → function reference (no execution) show() → function execution Functions in JS are values, just like numbers or strings You can pass functions around without calling them 📌 This difference is very important in: callbacks event handlers React props higher-order functions 💬 Your Turn Did you already know this difference? 😄 Comment “Clear now ✅” or “Didn’t notice this before 🤯” #JavaScript #LearnJS #FrontendDevelopment #CodingInterview #Functions #TechWithVeera #WebDevelopment
To view or add a comment, sign in
-
-
Day 42/100 – An Important JavaScript Concept Many People Ignore Not all performance issues come from bad code. Sometimes they come from too many function calls. 📌 Topic: Debouncing vs Throttling Both are used to control how often a function executes. ✅ Debouncing Runs the function only after a certain time has passed since the last event. Example use cases: • Search input • Form validation 👉 Executes when user stops typing. ✅ Throttling Runs the function at a fixed interval, no matter how many times the event occurs. Example use cases: • Scroll events • Window resize 👉 Executes every X milliseconds. Understanding these concepts helps build faster and smoother applications. Small improvements. Big impact. On to Day 43 🚀 #100DaysOfCode #JavaScript #WebDevelopment #LearningInPublic #Consistency #FrontendDevelopment
To view or add a comment, sign in
-
-
We often focus on component optimizations, but the biggest performance win often hides in plain sight: your initial JavaScript bundle size. I’ve seen production applications become orders of magnitude faster just by being ruthless with code splitting. It’s not about shipping less code *overall*, but about not delivering code until it's ABSOLUTELY necessary. Think route-level lazy loading, or even conditionally importing heavy third-party libraries. Audit your critical render path. If a component or dependency isn't needed for the first paint, defer it. Learn more about effective code splitting: https://lnkd.in/gh2A4yGw #FrontendPerformance #WebDevelopment #CodeSplitting #JavaScript
To view or add a comment, sign in
-
𝐓𝐨𝐝𝐚𝐲 𝐈 𝐫𝐞𝐯𝐢𝐬𝐢𝐭𝐞𝐝 𝐚 𝐜𝐨𝐫𝐞 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐜𝐨𝐧𝐜𝐞𝐩𝐭 𝐭𝐡𝐚𝐭 𝐪𝐮𝐢𝐞𝐭𝐥𝐲 𝐚𝐟𝐟𝐞𝐜𝐭𝐬 𝐜𝐨𝐝𝐞 𝐪𝐮𝐚𝐥𝐢𝐭𝐲: 𝒗𝒂𝒓 𝒗𝒔 𝒍𝒆𝒕 𝒗𝒔 𝒄𝒐𝒏𝒔𝒕 👇 var x = 10; // function-scoped let y = 20; // block-scoped const z = 30; // block-scoped & cannot be reassigned Key differences that matter in real projects: > "var" is function-scoped and can lead to unexpected bugs due to hoisting. > "let" provides block scope, making control flow safer. > "const" enforces immutability of the reference, improving readability. Modern JavaScript favors const by default, uses let when reassignment is required and avoids var in most cases. Back to fundamentals — with a modern JS lens. Any insights or suggestions are welcome🙂 #DAY6 #JavaScript #WebDevelopment #FrontendDevelopment #LearningInPublic #dailyChallenge
To view or add a comment, sign in
-
🤔 Quick JavaScript quiz! What do you think this logs? console.log(x); var x = 10; If you said undefined, you’re right ✅ Welcome to JavaScript hoisting. Hoisting means JS moves declarations (not values) to the top of their scope before running your code. Now try this 👇 console.log(y); let y = 10; 💥 Error! let and const are hoisted too, but live in the Temporal Dead Zone until declared. 👉 Rule of thumb: Hoisting is real, but clean, top-down code saves you from bugs. What tripped you up more when you were learning JS — var or let? 👀 #JavaScript #Frontend #WebDev #LearningInPublic
To view or add a comment, sign in
-
Today I explored some powerful JavaScript concepts that level up how code actually behaves behind the scenes: ✅ this keyword – Understanding how context works inside objects and functions. ✅ try...catch – Handling errors properly so programs don’t crash unexpectedly. ✅ Arrow Functions (=>) – Writing cleaner and shorter functions (and how this behaves differently inside them). ✅ setTimeout() – Running code after a delay. ✅ setInterval() – Running code repeatedly at fixed intervals. These topics helped me understand how JavaScript handles execution, timing, and errors — which are super important for real-world applications. Slowly building strong fundamentals 💻🔥 #JavaScript #WebDevelopment #LearningInPublic #100DaysOfCode #FrontendDevelopment
To view or add a comment, sign in
-
-
Why JavaScript doesn't crash when you call a function before defining it. 🧠 I recently dove deep into the "Execution Context" of JavaScript, and the concept of Hoisting finally clicked. If you’ve ever wondered why this code works: greet(); function greet() { console.log("Hello LinkedIn!"); } ...the answer lies in how the JS Engine treats your code before it even runs a single line. The Two-Phase Secret: Memory Creation Phase: Before the "Thread of Execution" starts, JavaScript scans your code and allocates memory for variables and functions. Functions are stored in their entirety in the Variable Environment. Variables (var) are stored as undefined. Code Execution Phase: Now, the engine runs the code line-by-line. Because the function is already sitting in the memory component, calling it on line 1 is no problem! The Key Takeaway: Hoisting isn't "moving code to the top" (that’s a common myth). It’s actually the result of the Memory Creation Phase setting aside space for your declarations before execution starts. Understanding the "how" behind the "what" makes debugging so much easier. #JavaScript #WebDevelopment #CodingTips #Hoisting #ProgrammingConcepts
To view or add a comment, sign in
-
-
const user = { name: 'Munsif', print: () => console.log(this.name) }; user.print(); If you think it prints "Munsif"... we need to talk. The `this` keyword is the silent killer of clean code. It changes based on *how* you call it, not *where* you write it. I just dropped a massive deep dive on my blog: "Demystifying the JavaScript 'this' Keyword." I peel back the layers on: 🔹 The 4 binding rules every dev must memorize 🔹 The exact reason the code above fails (and how to fix it) 🔹 The magic of `.bind()`, `.call()`, and `.apply()` 🔹 Tricky interview questions that trip everyone up Don't let context bugs haunt your PRs anymore. Link to the full breakdown: https://lnkd.in/gWMGP5Kn (The answer to the snippet is `undefined`. My blog explains why! 😉) #JavaScript #CodingChallenge #Frontend #DeveloperLife #JS
To view or add a comment, sign in
-
-
🎉 Just shipped my first JavaScript project! Built a Random Quote Generator in ~2 hours. Live: https://lnkd.in/dDxUUcRD What I learned: - Arrays store multiple items in one variable - Math.random() generates random numbers (Math.floor() rounds them down!) - document.getElementById() finds HTML elements - .textContent changes what's displayed - onclick connects buttons to functions What confused me at first: → Why commas are needed between array items → The difference between randomIndex and the actual quote Tech stack: HTML, CSS (Flexbox), JavaScript Next week: Building a CRUD To-Do List app Small wins add up! 💪 #100DaysOfCode #JavaScript #WebDevelopment #LearnInPublic
To view or add a comment, sign in
-
🚀 JavaScript Variables, Finally Decoded: var vs let vs const If you’ve ever wondered when to use var, let, or const, this breakdown makes it crystal clear. 💡 Key takeaways every JS developer should know: var is function-scoped and hoisted as undefined → easy to introduce bugs let and const are block-scoped → safer and more predictable const prevents reassignment (not immutability) let is perfect for loop counters and values that change Redeclaration errors = protection, not punishment 😄 ✅ Modern best practice Default to const Use let only when reassignment is required 🚫 Avoid var in modern JavaScript Cleaner scope. Fewer bugs. Happier future you. #JavaScript #WebDevelopment #Frontend #ProgrammingTips #ES6 #CleanCode #DevLife
To view or add a comment, sign in
-
More from this author
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