JavaScript How Web Works Interview Questions and Answers

Explain clients, servers, APIs, requests, responses, and the basic architecture behind web applications.

Frequently Asked Questions

Important questions are highlighted in the sections below; select one to jump to its answer.

Theoretical JavaScript Interview Questions

Front-end Back-end
What the user sees and interacts with directly The server logic, databases, and APIs users never see
Technologies: HTML, CSS, JavaScript, React, Vue Technologies: Node.js, Python (Django), Ruby (Rails), Go
Builds the UI - buttons, forms, layouts, animations Handles business logic, authentication, data storage
Runs in the user's browser Runs on a remote server or cloud
Focuses on design, speed, and responsive UX Read more Focuses on security, data integrity, and scalability Read more

const tells JavaScript "this binding won't change." You must assign a value immediately, and you can't reassign it later. This is why most style guides recommend const as your default choice - it signals intent clearly.

Here's the biggest misconception about const: it does NOT make values immutable. It only prevents reassignment of the variable itself. So a const object can still have its properties changed, and a const array can be pushed to. You just can't point the variable at a completely different object or array. If you need true immutability, look into Object.freeze().

The rest parameter (...) gathers any remaining arguments into a real array - function sum(...nums) {} means you can call it with any number of values. It must come last in the parameter list, and unlike the old arguments object, it gives you a proper array so all array methods work on it. Prefer rest over arguments in any modern code.

Same syntax (...), completely opposite jobs - context is everything. Spread expands: you're at a call site or inside a literal, pushing elements out. Rest collects: you're in a function signature or destructuring pattern, gathering elements in. Think of spread as 'unpack' and rest as 'pack'.

Just add ...args as your last (or only) parameter: function myFunc(first, ...rest) {}. Everything beyond first lands in rest as a real array - so you can immediately do rest.map(), rest.filter(), whatever you need. This replaces the old arguments hack and is much more readable.

An API (Application Programming Interface) defines how software components interact. SOAP uses XML with strict contracts. REST uses HTTP methods (GET, POST, PUT, DELETE) for CRUD on resources. A Request is a client message to the server. A Response is the server's reply. Request Body contains payload data. Query Params pass extra info in the URL. JSON and XML are common data formats.

Server-client architecture separates a web app into a server (data storage and logic) and a client (user interface). JavaScript on the client makes HTTP requests to the server, which processes them and returns data. This enables dynamic, data-driven web applications without full page reloads.

The browser resolves the site address, establishes a connection, and sends an HTTP request; the server responds with a status and resources such as HTML. The browser then processes the response and may request additional assets.

DNS looks up the network address associated with a domain name so the browser can connect to the appropriate server. Caching can let a client reuse a recent lookup.

An HTTP response includes a status code, headers, and optionally a body. The status communicates the outcome, headers carry metadata, and the body may contain the requested representation.

The rendering engine parses document and style information, builds representations such as the DOM and CSSOM, and uses them to lay out and paint the page. JavaScript can update the document and cause rendering work to be repeated.

HTTPS uses TLS to protect data in transit and authenticate the server through certificates. It does not by itself guarantee that a site is trustworthy or that its application is secure.

The critical rendering path is the sequence of browser work needed to turn HTML, CSS, and relevant scripts into the first rendered pixels. Resource discovery, parsing, style calculation, layout, and paint can all affect how quickly content appears.

DNS lookup and transport and TLS handshakes can add round trips before an HTTP request reaches the server. Reuse of established connections and modern protocols can reduce some setup costs, but performance depends on network and server conditions.

A client can send validators such as `ETag` or `Last-Modified` with a conditional request. If the resource has not changed, the server can reply `304 Not Modified`, allowing the client to reuse its cached body.

For requests that are not CORS-safelisted, the browser may first send an `OPTIONS` preflight asking whether the origin, method, and headers are allowed. The server's CORS response determines whether the browser proceeds with the actual request.

A controlling service worker can intercept eligible fetch requests and choose a cached response, make a network request, or combine strategies. It runs under browser security and lifecycle rules and does not make the network inherently available offline.