$ show sudheerj/javascript-interview-questions
This repository is a collection of JavaScript interview questions and coding exercises, accompanied by a Node.js script for automatically generating a table of contents in the README. The core content consists of standalone JavaScript files that illustrate specific language concepts and patterns, such as closures, hoisting, event loop, and functional programming techniques. The repository includes several reusable utility implementations that demonstrate advanced JavaScript patterns. Notably, the debounce and throttle functions provide robust solutions for rate-limiting event handlers, while the deep merge function safely handles circular references during object merging using a WeakMap for tracking. These utilities are self-contained, have no internal dependencies, and can be easily extracted for use in other projects. The project is actively maintained, as evidenced by a recent commit (though the date appears to be in the future, indicating the most recent activity). It relies on a single external dependency (github-slugger) for generating anchor links, and the build process is automated via a GitHub workflow. While the majority of the content serves educational purposes, the highlighted components exhibit strong craftsmanship and adhere to modern JavaScript best practices.
The LLM identified 3 files worth highlighting for reuse:
Implements a debounce function that delays execution of a callback until after a specified delay has elapsed since the last invocation. Uses closures to maintain a timeout ID and clearTimeout/setTimeout to manage the delay. Preserves function context and arguments via apply(). Demonstrates the debounce pattern for rate-limiting function calls in response to frequent events (e.g., search input, resize).
Implements a throttle function that ensures a callback executes at most once per specified time interval. Uses closures to track the last execution time and schedule future executions with setTimeout. Handles leading edge execution (immediate on first call) and schedules trailing edge if needed. Preserves context and arguments. Demonstrates the throttle pattern for controlling the rate of execution during continuous activity (e.g., scroll, resize).
Implements a deep merge function that combines two nested objects while safely handling circular references. Uses a WeakMap to track visited objects and prevent infinite recursion. Recursively merges objects and arrays, with values from the second object overriding on conflict. Returns a new object without mutating the inputs. Demonstrates advanced object merging with circular reference detection using WeakMap.