JavaScript Interview Question: What is the difference between Debouncing and Throttling? Answer: Both techniques control how often a function executes during frequent events. Debouncing: Executes a function after the user stops triggering the event. Throttling: Executes a function at fixed intervals while the event continues. Example (Debounce): 𝘧𝘶𝘯𝘤𝘵𝘪𝘰𝘯 𝘥𝘦𝘣𝘰𝘶𝘯𝘤𝘦(𝘧𝘯, 𝘥𝘦𝘭𝘢𝘺){ 𝘭𝘦𝘵 𝘵𝘪𝘮𝘦𝘳 𝘳𝘦𝘵𝘶𝘳𝘯 𝘧𝘶𝘯𝘤𝘵𝘪𝘰𝘯(){ 𝘤𝘭𝘦𝘢𝘳𝘛𝘪𝘮𝘦𝘰𝘶𝘵(𝘵𝘪𝘮𝘦𝘳) 𝘵𝘪𝘮𝘦𝘳 = 𝘴𝘦𝘵𝘛𝘪𝘮𝘦𝘰𝘶𝘵(𝘧𝘯, 𝘥𝘦𝘭𝘢𝘺) } } Explanation: Debouncing is useful for: 1. search inputs 2. auto-save features Throttling is useful for: 1. scroll events 2. window resizing Follow-up Interview Question: Why is debouncing important for API calls? Answer: Because it prevents multiple unnecessary API requests during rapid input changes. #javascript #WebPerformance #FrontendOptimization #SoftwareEngineering
Debouncing vs Throttling: JavaScript Techniques for Event Handling
More Relevant Posts
-
JavaScript Interview Question: What is Promise.race()? Answer: Promise.race() returns the result of the first promise that settles (resolved or rejected). Example: 𝘗𝘳𝘰𝘮𝘪𝘴𝘦.𝘳𝘢𝘤𝘦([𝘢𝘱𝘪𝘊𝘢𝘭𝘭(), 𝘵𝘪𝘮𝘦𝘰𝘶𝘵()]) Explanation: It is useful when implementing timeouts for API requests. Follow-up Interview Question: What happens if the first Promise rejects? Answer: The entire Promise.race() rejects immediately. #javascript #promises #AsyncProgramming #SoftwareEngineering
To view or add a comment, sign in
-
JavaScript Interview Question: How do you handle errors in Promises? Answer: Using .catch(). Example: 𝘧𝘦𝘵𝘤𝘩("/𝘢𝘱𝘪") .𝘵𝘩𝘦𝘯(𝘳𝘦𝘴 => 𝘳𝘦𝘴.𝘫𝘴𝘰𝘯()) .𝘤𝘢𝘵𝘤𝘩(𝘦𝘳𝘳 => 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘦𝘳𝘳𝘰𝘳(𝘦𝘳𝘳)) Explanation: .catch() handles errors from any previous promise in the chain. Follow-up Interview Question: Can errors inside .then() be caught by .catch()? Answer: Yes. Explanation: Errors thrown inside .then() propagate to .catch(). #javascript #promises #ErrorHandling #WebDevelopment
To view or add a comment, sign in
-
JavaScript Interview Question: What is the difference between async/await and Promises? Answer: async/await is syntax built on top of Promises that allows writing asynchronous code in a synchronous style. Example: 𝘤𝘰𝘯𝘴𝘵 𝘥𝘢𝘵𝘢 = 𝘢𝘸𝘢𝘪𝘵 𝘧𝘦𝘵𝘤𝘩("/𝘢𝘱𝘪") Explanation: async/await improves readability and reduces nested .then() chains. Follow-up Interview Question: Does async/await remove Promises internally? Answer: No. Explanation: async/await still uses Promises under the hood. #javascript #AsyncProgramming #WebDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
JavaScript Interview Question: What is the difference between Promises and Callbacks? Answer: Callbacks pass a function to execute after async operations. Promises represent the result of an async operation. Explanation: Promises provide: 1. better readability 2. error handling 3. chaining support Follow-up Interview Question: Why did callback hell occur? Answer: Because nested callbacks made code difficult to maintain. #javascript #AsyncProgramming #WebDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
JavaScript Interview Question: What is Promise.all()? Answer: Promise.all() runs multiple promises in parallel and resolves when all succeed. Example: 𝘗𝘳𝘰𝘮𝘪𝘴𝘦.𝘢𝘭𝘭([𝘧𝘦𝘵𝘤𝘩𝘜𝘴𝘦𝘳𝘴(), 𝘧𝘦𝘵𝘤𝘩𝘗𝘰𝘴𝘵𝘴()]) .𝘵𝘩𝘦𝘯(([𝘶𝘴𝘦𝘳𝘴, 𝘱𝘰𝘴𝘵𝘴]) => { 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨(𝘶𝘴𝘦𝘳𝘴, 𝘱𝘰𝘴𝘵𝘴) }) Explanation: If any Promise fails, Promise.all() immediately rejects. Follow-up Interview Question: When should you use Promise.all()? Answer: When multiple independent async tasks can run simultaneously. #javascript #promises #AsyncProgramming #FrontendDevelopment
To view or add a comment, sign in
-
🚨 JavaScript Interview Question What will be the output? console.log([] + []); console.log([] + {}); console.log({} + []); At first glance it looks simple. But the results are surprising because of JavaScript type coercion and how objects convert to strings. Understanding how JavaScript converts types internally is something that appears very often in frontend interviews. Many tricky bugs also come from this behavior. What output do you think this will produce?
To view or add a comment, sign in
-
JavaScript Interview Question: What is a Promise in JavaScript? Answer: A Promise is an object that represents the eventual completion or failure of an asynchronous operation. A Promise can be in three states: 1. pending 2. fulfilled 3. rejected Example: 𝘤𝘰𝘯𝘴𝘵 𝘱𝘳𝘰𝘮𝘪𝘴𝘦 = 𝘯𝘦𝘸 𝘗𝘳𝘰𝘮𝘪𝘴𝘦((𝘳𝘦𝘴𝘰𝘭𝘷𝘦, 𝘳𝘦𝘫𝘦𝘤𝘵) => { 𝘴𝘦𝘵𝘛𝘪𝘮𝘦𝘰𝘶𝘵(() => 𝘳𝘦𝘴𝘰𝘭𝘷𝘦("𝘋𝘰𝘯𝘦"), 1000) }) Explanation: Promises allow developers to handle asynchronous operations without deeply nested callbacks. They make async code easier to read and manage. Follow-up Interview Question: Why were Promises introduced in JavaScript? Answer: To solve problems like callback hell and better manage asynchronous workflows. #javascript #promises #AsyncProgramming #WebDevelopment
To view or add a comment, sign in
-
If you’re preparing for interviews, don’t just revise syntax. Understand behavior. Answer these without running the code 👇 🧠 𝟭. 𝗪𝗵𝗮𝘁 𝘄𝗶𝗹𝗹 𝘁𝗵𝗶𝘀 𝗹𝗼𝗴? 𝗪𝗵𝘆? 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨(𝘵𝘺𝘱𝘦𝘰𝘧 𝘕𝘢𝘕); 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨(𝘕𝘢𝘕 === 𝘕𝘢𝘕); If you hesitate here, revisit JavaScript’s number system. ⚡ 𝟮. 𝗢𝘂𝘁𝗽𝘂𝘁? 𝘭𝘦𝘵 𝘹 = 10; 𝘧𝘶𝘯𝘤𝘵𝘪𝘰𝘯 𝘵𝘦𝘴𝘵() { 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨(𝘹); 𝘭𝘦𝘵 𝘹 = 20; } 𝘵𝘦𝘴𝘵(); Why does it behave that way? (Hint: Temporal Dead Zone) 🔥 𝟯. 𝗪𝗵𝗮𝘁 𝗵𝗮𝗽𝗽𝗲𝗻𝘀 𝗵𝗲𝗿𝗲? 𝘤𝘰𝘯𝘴𝘵 𝘢𝘳𝘳 = [1, 2, 3]; 𝘢𝘳𝘳.𝘭𝘦𝘯𝘨𝘵𝘩 = 0; 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨(𝘢𝘳𝘳); Is this safe in production? When would this be dangerous? 🧩 𝟰. 𝗣𝗿𝗲𝗱𝗶𝗰𝘁 𝘁𝗵𝗲 𝗿𝗲𝘀𝘂𝗹𝘁: 𝘤𝘰𝘯𝘴𝘵 𝘢 = {}; 𝘤𝘰𝘯𝘴𝘵 𝘣 = { 𝘬𝘦𝘺: "𝘣" }; 𝘤𝘰𝘯𝘴𝘵 𝘤 = { 𝘬𝘦𝘺: "𝘤" }; 𝘢[𝘣] = 123; 𝘢[𝘤] = 456; 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨(𝘢[𝘣]); This question silently tests object keys and coercion. 🚀 𝟱. 𝗔𝗿𝗰𝗵𝗶𝘁𝗲𝗰𝘁𝘂𝗿𝗲 𝗾𝘂𝗲𝘀𝘁𝗶𝗼𝗻 When should you avoid using async/await and prefer Promise chaining? Real-world scenario only. If you can explain why behind each answer, you’re interview-ready. If not — good. Now you know what to fix. Drop your answers below 👇 #javascript #frontenddeveloper #codinginterview #webdevelopment #engineering #DAY76
To view or add a comment, sign in
-
JavaScript Interview Question: What is Promise.allSettled()? Answer: Promise.allSettled() waits for all promises to finish regardless of success or failure. Example: 𝘗𝘳𝘰𝘮𝘪𝘴𝘦.𝘢𝘭𝘭𝘚𝘦𝘵𝘵𝘭𝘦𝘥([𝘱𝘳𝘰𝘮𝘪𝘴𝘦1, 𝘱𝘳𝘰𝘮𝘪𝘴𝘦2]) Explanation: It returns an array of objects describing each promise result. Follow-up Interview Question: When should you use Promise.allSettled() instead of Promise.all()? Answer: When you need results from all promises even if some fail. #javascript #promises #AsyncProgramming #WebDevelopment
To view or add a comment, sign in
-
🚀 Day 23/100 – #100DaysOfCode JavaScript Interview Questions (Advanced Concepts) Continuing with JavaScript fundamentals, today I reviewed some important interview questions that test a deeper understanding of how JavaScript works under the hood. 🔹 Hoisting Hoisting is JavaScript’s behavior where variable and function declarations are moved to the top of their scope before execution. var is hoisted with undefined, while let and const are hoisted but remain in the temporal dead zone. 🔹 Callback Function A callback is a function passed as an argument to another function, which is executed later. Commonly used in: -Asynchronous operations (API calls) -Event handling 🔹 Closure A closure is a function that remembers variables from its lexical scope even after the outer function has finished execution. This is heavily used in: -Data encapsulation -Maintaining private variables 🔹 Pass by Value vs Pass by Reference Pass by Value: A copy of the value is passed (Primitive types) Pass by Reference: A reference to the original object is passed (Objects, Arrays) Changes in reference types affect the original data, while primitive changes do not. Understanding these concepts is critical because they often separate beginners from intermediate developers in interviews. 23 days down, 77 more to go. #Day23 #100DaysOfCode #JavaScript #FrontendDevelopment #WebDevelopment #CodingInterview #MERN
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