
JavaScript Fundamentals — Practice Questions & Implementations
javascript-fundamentals-practice-questions-and-implementationsA practical TypeScript-first guide to JavaScript fundamentals with 15 from-scratch implementations: array and promise polyfills, debounce/throttle, curry, deep clone/equal, data merge, and generator patterns with tests.
A curated collection of JavaScript fundamentals implemented from scratch in TypeScript. Each topic includes a working implementation with test cases — built for interview prep and deep understanding.
Repository: github.com/RohanGau/js-fundamentals
Table of Contents
Array Polyfills
1. Array.prototype.map
Implement Array.prototype.map from scratch. Handles sparse arrays, thisArg, and callback validation — matching native spec behavior.
Key concepts: Prototype extension, Object(this), >>> unsigned right shift, call with thisArg
| Link | |
|---|---|
| Implementation | src/polyfills/arrayMap.ts |
| Tests | src/__tests__/arrayPolyfills.test.ts |
2. Array.prototype.filter
Implement Array.prototype.filter from scratch. Returns a new array with elements that pass the predicate test.
Key concepts: Prototype extension, sparse array handling, immutability
| Link | |
|---|---|
| Implementation | src/polyfills/arrayFilter.ts |
| Tests | src/__tests__/arrayPolyfills.test.ts |
3. Array.prototype.reduce
Implement Array.prototype.reduce from scratch. Accumulates array values into a single result using a callback.
Key concepts: Accumulator pattern, initial value handling, empty array edge case
| Link | |
|---|---|
| Implementation | src/polyfills/arrayReduce.ts |
| Tests | src/__tests__/arrayPolyfills.test.ts |
Promise Polyfills
4. Promise.all
Implement Promise.all from scratch. Resolves when all promises fulfill (preserving order) or rejects on the first failure.
Key concepts: Promise coordination, order preservation, short-circuit rejection
| Link | |
|---|---|
| Implementation | src/polyfills/promiseAll.ts |
| Tests | src/__tests__/promisePolyfills.test.ts |
5. Promise.any
Implement Promise.any from scratch. Returns the first fulfilled promise or throws AggregateError when all reject.
Key concepts: First-success pattern, AggregateError, inverse of Promise.all
| Link | |
|---|---|
| Implementation | src/polyfills/promiseAny.ts |
| Tests | src/__tests__/promisePolyfills.test.ts |
Utility Functions
6. classNames
Build a classNames/clsx utility from scratch. Merges CSS class names from strings, objects, arrays, and functions — with truthy/falsy toggling.
Key concepts: Recursive type handling, conditional class toggling, variadic arguments
| Link | |
|---|---|
| Implementation | src/polyfills/classNames.ts |
| Tests | src/__tests__/classNames.test.ts |
7. Flatten
Flatten a nested array of arbitrary depth without mutating the original. Uses an explicit stack to avoid recursion depth limits.
Key concepts: Stack-based iteration vs recursion, depth handling, immutability
| Link | |
|---|---|
| Implementation | src/polyfills/flatten.ts |
| Tests | src/__tests__/flatten.test.ts |
Core Patterns
8. Debounce
Implement debounce — delays function execution until after a specified wait period has elapsed since the last call.
Key concepts: setTimeout/clearTimeout, this context preservation, closures
| Link | |
|---|---|
| Implementation | src/core/debounce.ts |
9. Throttle
Implement throttle — limits function execution to at most once per specified interval.
Key concepts: Rate limiting, leading/trailing invocation, timing control
| Link | |
|---|---|
| Implementation | src/core/throttle.ts |
10. Curry
Implement function currying — transforms a multi-argument function into a sequence of single-argument functions.
Key concepts: Closures, Function.length (arity), argument accumulation, partial application
| Link | |
|---|---|
| Implementation | src/core/curry.ts |
11. Deep Clone
Deep clone JavaScript values while preserving prototypes, symbol keys, and handling circular references.
Key concepts: Recursion, WeakMap for circular refs, Reflect.ownKeys, prototype preservation, prototype pollution defense
| Link | |
|---|---|
| Implementation | src/core/deepClone.ts |
12. Deep Equal
Implement deep equality comparison for primitives, arrays, and objects — handling type mismatches and nested structures.
Key concepts: Recursive comparison, typeof limitations with arrays, structural equality vs referential equality
| Link | |
|---|---|
| Implementation | src/core/deepEqual.ts |
| Tests | src/__tests__/deepEqual.test.ts |
13. Data Merge
Merge an array of session objects by user ID — summing durations and deduplicating equipment lists.
Key concepts: Map for grouping, Set for deduplication, data transformation
| Link | |
|---|---|
| Implementation | src/core/dataMerge.ts |
| Tests | src/__tests__/dataMerge.test.ts |
Advanced Concepts
14. Generators
Generator functions and iteration patterns — yield, delegation with yield*, and infinite sequences with idMaker.
Key concepts: Generator protocol, yield/yield*, lazy evaluation, iterator protocol
| Link | |
|---|---|
| Implementation | src/core/generatorExamples.ts |
15. Promise.all Demo
Practical demo of coordinating multiple async operations with Promise.all.
Key concepts: Async orchestration, parallel execution, error handling
| Link | |
|---|---|
| Implementation | src/core/promiseAllDemo.ts |
How to Run
# Clone the repo
git clone https://github.com/RohanGau/js-fundamentals.git
cd js-fundamentals
# Install dependencies
npm install
# Run all tests
npm test
# Watch mode (re-runs on save)
npm run test:watch
# Run in browser
npm run serve
Tech Stack
- TypeScript — Strict mode, full type safety
- Vitest — Fast unit testing
- ESM — Modern module system
- Zero dependencies — No frameworks
Want to Contribute?
Feel free to open a PR to add new topics, improve existing implementations, or add more test cases.
Repository: github.com/RohanGau/js-fundamentals
Built by Rohan for learning JavaScript fundamentals the right way.
Links
- Repository(Repository)



