JavaScript Interview

Performance, Browser APIs, Rendering & Modern Web Architecture

JavaScript interview questions covering error propagation, timers, browser rendering, performance, code splitting, tree shaking, browser observers, routing, SSR, CSR and hydration.

25 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

25 Results
151
SeniorAdvanced

What is the difference between synchronous exceptions and Promise rejections?

A synchronous exception is thrown while ordinary JavaScript code is executing and can be caught by a surrounding synchronous try/catch. A Promise rejection represents failure of an asynchronous Promise operation and must be handled through await inside try/catch or with a rejection handler such as catch.

152
SeniorAdvanced

What is an unhandled Promise rejection?

An unhandled Promise rejection occurs when a Promise rejects and the application does not attach an appropriate rejection handler within the runtime's handling rules. In browsers and server runtimes this can produce warnings, diagnostic events, or process-level consequences depending on the environment.

153
SeniorAdvanced

What is the difference between setTimeout() and setInterval()?

setTimeout schedules a callback to run once after at least the specified delay. setInterval repeatedly schedules a callback at approximately the specified interval until it is canceled.

154
SeniorAdvanced

Why does setTimeout(fn, 0) not execute immediately?

A zero-millisecond timeout means the callback becomes eligible to run after the minimum scheduling delay; it does not interrupt currently executing JavaScript. The callback is placed into the runtime's task scheduling mechanism and must wait for the current call stack and relevant microtasks to finish.

155
SeniorAdvanced

What is requestAnimationFrame()?

requestAnimationFrame asks the browser to run a callback before a future repaint. It is designed for visual updates and animation work because the browser can coordinate callbacks with its rendering cycle.

156
SeniorAdvanced

What is the browser rendering pipeline at a high level?

At a high level, the browser parses HTML and CSS, builds structures needed for rendering, calculates layout, paints visual content, and composites layers for display. JavaScript can trigger changes that require some of these stages to run again.

157
SeniorAdvanced

What are reflow/layout and repaint?

Layout, historically called reflow in many discussions, calculates the size and position of elements when geometry may have changed. Paint determines how visual parts such as text, borders, backgrounds, and shadows should be drawn.

158
SeniorAdvanced

What is layout thrashing?

Layout thrashing occurs when JavaScript repeatedly alternates DOM writes that invalidate layout with reads that require up-to-date layout information. The browser may be forced to perform synchronous layout calculations many times.

159
SeniorAdvanced

What is the difference between defer and async on script elements?

Both attributes allow an external classic script to be downloaded without blocking HTML parsing in the normal way. An async script executes as soon as it is available, so execution order relative to other async scripts is not guaranteed.

160
SeniorAdvanced

What is code splitting?

Code splitting divides an application bundle into smaller pieces that can be loaded when required instead of sending all JavaScript during the initial page load. This can reduce initial download, parsing, and execution costs.

161
SeniorAdvanced

What is tree shaking?

Tree shaking is a build-time optimization that removes code determined to be unused from the final bundle. It works best with statically analyzable ES module imports and exports.

162
SeniorAdvanced

What is minification?

Minification reduces JavaScript file size by removing unnecessary whitespace and comments and by applying safe code transformations such as shortening local identifiers where appropriate.

163
SeniorAdvanced

What is a source map?

A source map maps generated or transformed JavaScript back to the original source files and locations. It is useful when code has been bundled, transpiled, or minified.

164
SeniorAdvanced

What is transpilation in JavaScript?

Transpilation converts source code from one JavaScript form into another, often to support environments that do not understand newer syntax directly. Tools such as Babel can transform selected modern language features according to configured browser targets.

165
SeniorAdvanced

What is a polyfill?

A polyfill supplies an implementation of a web or JavaScript API that is missing from a target environment. It differs from transpilation, which primarily rewrites syntax.

166
SeniorAdvanced

What is feature detection?

Feature detection checks whether the runtime supports a required capability before using it. It is generally more reliable than guessing capabilities from the browser's user-agent string.

167
SeniorAdvanced

What is IntersectionObserver?

IntersectionObserver asynchronously reports when a target element enters or leaves the intersection of a root viewport or ancestor. It is commonly used for lazy loading, visibility tracking, and triggering work when content approaches the viewport.

168
SeniorAdvanced

What is MutationObserver?

MutationObserver watches a DOM subtree for configured changes such as child additions/removals, attribute changes, or text mutations. The observer receives mutation records asynchronously.

169
SeniorAdvanced

What is ResizeObserver?

ResizeObserver reports changes to the dimensions of observed elements. It allows components to respond to their actual rendered size rather than relying only on global window resize events.

170
SeniorAdvanced

What is the History API?

The History API allows browser applications to interact with session history. pushState adds a history entry without performing a full page navigation, while replaceState replaces the current entry.

171
SeniorAdvanced

What is the difference between window.location and the History API?

window.location represents the current document URL and can be used to navigate, reload, or inspect URL components. Assigning a new location normally causes browser navigation and document loading.

172
SeniorAdvanced

What is client-side routing?

Client-side routing maps URL paths to application views without requiring a complete document reload for every navigation. It is common in single-page applications.

173
SeniorAdvanced

What is the difference between client-side rendering and server-side rendering?

Client-side rendering sends enough HTML and JavaScript for the browser to build or update much of the user interface after scripts execute. Server-side rendering generates HTML on the server for the request and sends that rendered markup to the browser.

174
SeniorAdvanced

What is hydration in modern web applications?

Hydration is the process in which client-side JavaScript attaches application behavior and event handling to HTML that was already rendered on the server. This allows users to receive initial markup quickly while still gaining rich client-side interactivity.

175
SeniorAdvanced

How would you diagnose a slow JavaScript web page in production?

Start by measuring rather than guessing. Use browser performance tools, network traces, runtime profiling, real-user monitoring, and application telemetry to identify whether the bottleneck is network transfer, JavaScript execution, rendering, API latency, memory growth, or another dependency.