Day 29 - Debounce Today I implemented debounce from scratch. Understanding how to control function execution timing is crucial for handling frequent events like input and scroll. Writing it without libraries clarified the underlying logic. Debounce resets the timer on every call. It protects your Backend (API calls) and your Frontend (Rendering). It relies on Closures and setTimeout . #JavaScript #MachineCoding #Frontend #Debounce #Backend
Implementing Debounce from Scratch in JavaScript
More Relevant Posts
-
I used to think custom hooks were just… fancy function wrappers 🤷♂️ My first reaction was: “Wait… we’re just grouping useState and useEffect in a separate file and calling it a hook?” 🤔 And yeah - technically, that’s true. But here’s what I completely missed 👇 Not every grouped logic needs to be a custom hook. I started creating: -- useToggle, useCounter, useFormInput For. Everything. 😅 My hooks folder was growing faster than my actual components 📁📈 That’s when I realized something important: The real power of custom hooks isn’t abstraction itself - it’s when and why you abstract. Here’s my rule now: ✅ Is this logic complex AND reused? → Custom hook ✅ Is it shared across multiple components? → Custom hook ❌ Is it just 3 lines of state? → Keep it in the component 🚨 Am I building this “just in case”? → Stop right there Abstraction should reduce mental load 🧠 Not increase file count 📁 Clean code isn’t about how many hooks you can create. It’s about how easily someone can understand your component at 11:30 PM during a production bug call 🔥 Less clever. More clear. #React #JavaScript #WebDev #CleanCode
To view or add a comment, sign in
-
Still using JavaScript arrays the same way you always have? Modern array methods can make everyday tasks simpler and your code easier to read. This covers practical tips to help you: • Replace values cleanly • Reset arrays without workarounds • Convert arrays into objects • Sum values efficiently • Find the last occurrence of elements Small improvements like these add up quickly in real projects. Which array method do you rely on most? [Check the Link in the Comment! 🔗] #JavaScript #WebDevelopment #Frontend #CodingTips #ArrayMethods #DevTips #Syncfusion
To view or add a comment, sign in
-
New Default Asset Pipeline: Propshaft After more than a decade, Sprockets is no longer the default. Rails 8 introduces Propshaft a lean, modern asset pipeline. It focuses on: • Clear asset paths • Digest stamping for caching • Simplicity Complex JavaScript bundling is now expected to be handled by: • esbuild • Vite • Other modern tools Rails is embracing a cleaner separation of concerns. Lean backend. Modern frontend tooling. #rails #frontend #ruby #webdevelopment #javascript
To view or add a comment, sign in
-
⚛️ React.js Component Patterns Cheat Sheet A quick reference for: ✅ Presentational & container components ✅ Higher-order components (HOC) ✅ Render props ✅ Compound components ✅ Controlled vs uncontrolled ✅ Custom hooks ✅ Forwarding refs ✅ Error boundaries ✅ Portals ✅ Best practices Save & share with your team! The Complete Dev Roadmap with SaaS Boilerplate ➡️ https://champ.ly/-FLdfic_ --- If you found this guide helpful, follow TheDevSpace for more tips, tutorials, and cheat sheets on web development. Let's stay connected! 🚀 Also follow 👉 W3Schools.com & JavaScript Mastery for free tutorials on web development. #React #Patterns #JavaScript #WebDevelopment #CheatSheet #Frontend #Coding
To view or add a comment, sign in
-
DOM manipulation is where JavaScript stops being theory and starts controlling reality. Turning static HTML into something alive — changing content, tweaking styles, creating elements, deleting chaos. That’s not just code. That’s power. From getElementById() to createElement() — if you understand the DOM deeply, you’re not “learning JS”… you’re commanding the browser. Build it. Break it. Rebuild it better. #JavaScript #DOM #WebDevelopment #Frontend #CodingJourney #LearnToCode
To view or add a comment, sign in
-
-
Closure behavior with asynchronous code Consider: for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 1000); } Output: 3 3 3 Reason: var is function scoped. All callbacks reference the same variable. When loop finishes: i = 3 Solution using let: for (let i = 0; i < 3; i++) { setTimeout(() => console.log(i), 1000); } Output: 0 1 2 let creates new binding each iteration. Understanding lexical scope is essential for predictable behavior. #javascript #frontend
To view or add a comment, sign in
-
🤯 This JavaScript snippet will catch you off guard... const obj = { value: 10, double() { return this.value * 2; } }; const { double } = obj; console.log(double()); // What do you think prints? 💭 Most developers say 20. The real answer? NaN. Here's why 👇 When you destructure double from obj, it loses its this binding. Called as a plain function, this no longer points to obj — it points to undefined (strict mode) or the global object (non-strict), where value doesn't exist. So this.value becomes undefined, and undefined * 2 = NaN. ✅ Let me know how will you fix it before the console. The rule to remember: A method is only bound to its object when called AS a method (obj.double()). The moment you detach it, this is gone. This trips up even experienced developers. How many of you got it right? 👇 #JavaScript #WebDev #Frontend #JSInterviewTips #CodingTips #InterviewExperience
To view or add a comment, sign in
-
This small filter() mistake is hurting your JavaScript readability. Most developers write: Returning true or false inside an unnecessary if/else. But filter() already expects a boolean. Return the condition directly. Less noise. More clarity. Cleaner code. Readable code > clever code. Do you prefer explicit returns or implicit ones? 👇 #JavaScript #WebDevelopment #CleanCode #SoftwareEngineering #Frontend
To view or add a comment, sign in
-
🌱 Going back to basics "Uncontrolled Components" Yesterday I wrote about "Controlled Components". Today, let’s talk about the other side "Uncontrolled Components". Not everything needs to be controlled by state. Sometimes, the input can manage its own value, and we just read it when needed. Using "ref", we can directly access the input value without syncing every change with React state. A "ref" gives us direct access to the DOM element. Instead of storing every keystroke in state, we simply read the value when we actually need it like "on submit". Less wiring. Less state management. Sometimes less headache Uncontrolled components are useful when: - You don’t need instant validation - You only need the value on submit - The form logic is simple "Controlled components" give clarity. "Uncontrolled components" give simplicity. Going back to basics is also about knowing when to control and when to let go. Both have their place. #ReactJS #Frontend #JavaScript #GoingBackToBasics #LearningInPublic
To view or add a comment, sign in
-
-
Stop Shipping "Ghost Code" 👻 – Meet Knip! Is your codebase becoming a graveyard for unused files and "just in case" exports? 🏚️ As projects grow, we often leave behind dead code: exports that aren't imported anywhere, dependencies that are no longer used, and files that are just taking up space. This doesn't just look messy— hurts your bundle size, slows down CI/CD pipelines, and confuses new developers. Enter Knip ✂️ – the ultimate "dust-buster" for your JavaScript and TypeScript projects. What does Knip actually find? ✅ Unused Files: Clean up those orphaned .ts or .js files. ✅ Unused Dependencies: Identify packages in package.json that are just sitting there. ✅ Unused Exports: Find functions/types you exported but never actually used. ✅ Duplicate Exports: Spot redundant code before it becomes a headache. Why I’m a fan: Unlike many other tools, Knip is incredibly smart. It understands monorepos, supports major frameworks (React, Next.js, Svelte, etc.), and integrates seamlessly with your existing tools like ESLint and Prettier. How to get started in 10 seconds: To install: `npm install knip` To check: `npx knip` That’s it. No complex configuration is needed to get your first report. A clean codebase isn’t just about aesthetics; it’s about performance and maintainability. If you haven't audited your project recently, give Knip a try today! Have you used Knip before? What’s the biggest "dead code" monster you’ve uncovered? Let me know in the comments! 👇 #WebDevelopment #TypeScript #JavaScript #CleanCode #OpenSource #SoftwareEngineering #WebPerf #Knip Thanks to Lars Kappert
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