Almost Hired! The One JavaScript Mistake That Got Poonam Rejected

Chirag Goel
3 min readFeb 26, 2025

--

JavaScript coding interviews are a test of both technical skills and problem-solving ability. Let’s explore an engaging interview scenario between Chirag, an experienced interviewer, and Poonam, a skilled frontend developer eager to land her next role.

The Interview Begins

Interviewer (Chirag): “Welcome, Poonam! Today, we’ll work on a frontend JavaScript problem to assess your problem-solving approach and coding skills. Are you ready?”

Candidate (Poonam): “Absolutely, Chirag. Let’s get started!”

Chirag: “Great! Here’s your problem: Implement an infinite scrolling feature in vanilla JavaScript. You need to detect when the user reaches the bottom of the page and fetch more content dynamically.”

The Thought Process

Poonam begins by outlining her approach:

  • She explains the concept of infinite scrolling and how it enhances user experience.
  • She discusses event listeners, specifically using the scroll event on the window.
  • She considers debouncing to optimize performance and avoid excessive API calls.

She then writes her implementation:

function loadMoreContent() {
console.log("Fetching more data...");
// Simulate API call and content appending
}
document.addEventListener("scroll", function () {
if (window.innerHeight + window.scrollY >= document.body.offsetHeight) {
loadMoreContent();
}
});

Challenges and Refinements

While her initial solution works, Chirag raises some points for improvement:

  1. Performance Optimization: The event fires on every scroll movement. Poonam refactors it using a debounce function.
  2. Edge Cases: What happens if the user scrolls too fast, or if the API takes too long?
  3. Error Handling: She implements a loading state and handles API failures gracefully.

Poonam refines her code:

function debounce(func, delay) {
let timer;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => func.apply(this, args), delay);
};
}
function loadMoreContent() {
console.log("Fetching more data...");
// Simulate API call and content appending
}
document.addEventListener("scroll", debounce(function () {
if (window.innerHeight + window.scrollY >= document.body.offsetHeight) {
loadMoreContent();
}
}, 200));

The Feedback Session

Chirag: “Great job, Poonam! Let’s go over your solution.”

Strengths

Clear understanding of event handling and scroll detection.Refactored code for better performance using debouncing.Considered error handling and edge cases.

Areas for Improvement

Consider using the IntersectionObserver API instead of scroll events for better performance.Ensure proper cleanup of event listeners to prevent memory leaks.Optimize for mobile users where scrolling behavior might differ.

Key Takeaways

🔹 Performance Matters

  • Use debouncing or throttling to optimize event handling.
  • Reduce unnecessary reflows and repaints in the DOM.

🔹 Think About Scalability

  • Consider alternatives like IntersectionObserver for modern browsers.
  • Implement proper cleanup to avoid performance bottlenecks.

🔹 Error Handling is Crucial

  • Always account for API failures and edge cases.
  • Provide a smooth user experience even when data fetching fails.

Final Words from Chirag

Chirag: “Poonam, you have a great approach to problem-solving. Keep refining your skills and thinking about scalability and performance optimization. Well done!”

Frontend interviews aren’t just about coding — they’re about designing efficient and user-friendly solutions. Keep learning, practicing, and optimizing! 🚀

KodeKarma

Looking to take your coding skills to the next level? kodekarma.dev is your go-to platform for practicing frontend coding challenges. With curated problems, real-world scenarios, and guidance tailored for all levels, KodeKarma helps you prepare smarter and faster. Start your journey to interview success today!

--

--

Chirag Goel
Chirag Goel

Written by Chirag Goel

Senior Software Engineer @Microsoft | Blogger | Youtuber | Mentor | Entrepreneur. I’m the intersection of Technology, Business and Design.

Responses (1)

Write a response