=== compares value + type; == coerces the operands following a fixed algorithm before comparing. Always use === except for one defensible idiom: `x == null` to check for null OR undefined.
Category
Closures, async, prototypes, modules, and language internals.
72 questions
=== compares value + type; == coerces the operands following a fixed algorithm before comparing. Always use === except for one defensible idiom: `x == null` to check for null OR undefined.
Can block JavaScript execution while running.
Can you explain hoisting in JavaScript? For example: output of the below code.
Debounce delays the call until activity stops; throttle caps how often the call can fire. Both control noisy events but solve different problems.
Shallow copy duplicates the top level; nested objects are still shared references. Deep copy recursively duplicates every level. Use `structuredClone` for a correct, fast deep copy.
`var` is function-scoped and hoisted to `undefined`. `let`/`const` are block-scoped with a temporal dead zone. `const` forbids reassignment but the value can still be mutated.
Arrow functions inherit `this`/`arguments` lexically, can't be used with `new`, and have no `prototype`. Regular functions get their own `this` based on the call site and can be constructors.
Difference between map and object in JavaScript
Difference between Prototypal and Classical Inheritance in JavaScript
Shallow copy duplicates the top-level container but reuses inner references. Structural sharing reuses every untouched subtree across versions — the basis of efficient immutable data.
Error handling in async JavaScript
ESM is statically analyzable, async, the standard. CJS is dynamic, sync, Node-historical. Modern code is ESM; CJS lives on for legacy compatibility. Mixing them is the source of many Node interop bugs.
Event propagation in JavaScript: bubbling vs capturing
`this` is determined at call time by how the function is invoked. `call`/`apply` invoke immediately with a chosen `this`; `bind` returns a new function permanently bound to it.
Explain the concept of server-side rendering (SSR) in Next.js.
Explain the prototype chain and how Razorpay's SDK can extend native objects without breaking merchant code.
Every object has an internal `[[Prototype]]` link to another object. Property lookup walks that chain. `Object.create`, `class`, and constructor functions all set up the same chain.
Recurse with reduce + concat for clarity, or iterate with a stack to avoid stack overflow on deep nesting. Support a depth parameter to match Array.prototype.flat semantics.
Function declarations are fully hoisted (callable before the line). `var` is hoisted and initialized to undefined. `let`/`const`/`class` are hoisted but uninitialized — accessing them before the declaration throws (Temporal Dead Zone).
How async/await works in JavaScript
How do we use OOP in JavaScript
How do you handle asynchronous code using async/await and Promises
How do you handle errors if multiple requests are sent simultaneously
How do you send multiple API requests on a single button click
How does "this" behave in Node.js? Is it the same as in a browser console
How does event delegation work in JavaScript? Why is it efficient
How does JavaScript handle asynchronous operations? What mechanisms does it use
How does Next.js automatic code splitting and SSR work
How does Next.js handle environment variables (.env.local vs .env.production)
How does useActionState manage async actions and form state
async/await is syntax sugar over promises and generators. `await` pauses the function, yields to the microtask queue, and resumes when the promise settles. Same semantics, dramatically better readability and error handling.
How is Promise.allSettled different and when would you use it
How would you prepare DOM manipulation, event listeners, and styling with vanilla JS
If a token is saved in localStorage, anyone can misuse it — what should you do
Return a function that resets a timer on every call and only invokes fn after `wait` ms of silence. Forward `this` and arguments, expose cancel/flush, and optionally support a leading-edge call.
Implement a polyfill for Array.prototype.reduce
Return a new function that calls the original with a fixed `this` and partially applied args. Handle the `new`-as-constructor case so the bound `this` is ignored when called with `new`.
Map each input to a promise that resolves with {status:'fulfilled', value} on success or {status:'rejected', reason} on failure. Pass the wrapped array to Promise.all so the outer promise never rejects.
Map<event, Set<handler>>. on/off/emit, with `on` returning an unsubscribe function. Handle errors per-handler so one throw doesn't break the rest. Bonus: once, namespacing, wildcard.
Maintain an active count and a waiting queue. Each enqueue returns a promise; when active < K, run; otherwise wait. On finish, pull the next waiter. Bonus: cancellation, retries, prioritization.
Implement an async scheduler with max concurrency
Return a function that either accepts another argument and returns itself, or returns the running total when called with no argument. Implementation hinges on closure + a base case.
Implement memoization for an async function with callbacks (cache, deep equality, parallel calls)
State machine: pending → fulfilled or rejected (transitions once). then/catch/finally chain by returning a new Promise. Resolve thenables. Schedule callbacks as microtasks (queueMicrotask) to match spec timing.
JavaScript script loading strategies (defer, async, modulepreload)
Object: keys are strings/symbols, key order is mostly insertion (with integer-key quirks), prototype chain pollution. Map: any key type (objects, NaN), guaranteed insertion order, .size in O(1), better for frequent add/remove. Use Map for dictionaries; Object for shaped records.
Object reference vs primitive comparison in JavaScript
Output-based JS questions on Promises and async behavior
`call(thisArg, ...args)` invokes immediately with a given `this`. `apply(thisArg, argsArray)` is the same but with args as an array. `bind(thisArg, ...partials)` returns a new function with `this` permanently set. The polyfill closes over `thisArg` + partials and uses `apply` (or `call`) internally — plus a `new.target` check so the bound function still works as a constructor.
all = fail-fast aggregation. allSettled = collect every outcome. race = first to settle (resolve or reject). any = first to *resolve*, ignores rejections until all fail.
A Promise is a placeholder for a future value — pending → fulfilled or rejected, settled once. For multiple async ops: `Promise.all` (fail-fast parallel), `Promise.allSettled` (parallel, never rejects, returns per-result status), `Promise.race` (first to settle), `Promise.any` (first to fulfill, ignores rejections). Use `for await…of` or a worker pool when you need bounded concurrency.
Release strategy for a JS library (semver, changesets)
Search bar with debounce + async suggestions — how do you architect it
Spread expands an iterable/object into elements; rest collects the remainder into an array/object. Destructuring binds positions/keys to variables with optional defaults and renames. All shallow — nested values still share references.
Type definitions for a JS library — strategies
What algorithm does Array.prototype.sort() use? What’s the output of [1, null, 5, 2, undefined]
A closure is a function bundled with the variables in scope at the time it was created — it remembers and can mutate those variables long after the outer function has returned.
What are Promises in JavaScript
What happens if a browser tab reaches its memory limit
What is a Promise in JavaScript? How do you resolve a Promise, and what are its use cases
What is closure? Where have you used it
What is currying in JavaScript
What is the use of the new operator in JavaScript
Top-level `this` in a script is the global object (`window` in browsers, `globalThis` in Node sloppy). In ES modules and strict mode it's `undefined`. Inside functions, it depends on how they're called; arrows inherit lexically.
Write a custom debounce function in JavaScript
Write a custom implementation of Function.prototype.bind.
Write a polyfill for Function.prototype.bind
Write a polyfill for Promise.all handling both resolve and reject cases.
Write a program to create a promise and an async/await function.
Dedupe with a Set, then sort. One-liner: [...new Set(arr)].sort((a,b)=>a-b). The catch interviewers test: default .sort() is lexicographic, so you MUST pass a numeric comparator for numbers.
Write a promise method that is resolving something.
Write code to find frequency of elements in an array