How the web works
Foundations every web developer is expected to know.
Q1.What happens when you type a URL into the browser and press Enter?
The browser checks its cache, then resolves the domain to an IP through DNS. It opens a TCP connection (or QUIC for HTTP/3), performs the TLS handshake for HTTPS and sends an HTTP request. The server responds with HTML, which the browser parses into the DOM, fetches CSS, JavaScript and images, builds the render tree, lays out the page and paints it.
Q2.What is DNS?
The Domain Name System translates names like example.com into IP addresses. Resolvers query root, top-level domain and authoritative name servers and cache the answer for the record's TTL.
Q3.What are the common DNS record types?
A maps a name to an IPv4 address, AAAA to IPv6, CNAME aliases one name to another, MX points to mail servers, TXT holds text such as SPF or verification codes, and NS lists the name servers for the domain.
Q4.What is the difference between HTTP and HTTPS?
HTTPS is HTTP over TLS. It encrypts traffic, protects it from tampering and proves the server's identity with a certificate. Browsers mark plain HTTP sites as not secure, and HTTPS is required for many modern APIs.
Q5.What are the main HTTP methods?
GET reads data, POST creates or triggers an action, PUT replaces a resource, PATCH updates part of it, DELETE removes it. HEAD and OPTIONS are used for metadata and CORS preflight requests.
Q6.Name the HTTP status code groups with examples.
1xx informational, 2xx success (200 OK, 201 Created, 204 No Content), 3xx redirects (301 permanent, 302 and 307 temporary, 304 Not Modified), 4xx client errors (400, 401, 403, 404, 429), 5xx server errors (500, 502, 503, 504).
Q7.What is the difference between a 301 and a 302 redirect?
A 301 is permanent: browsers cache it and search engines pass ranking signals to the new URL. A 302 is temporary, so search engines keep the original URL indexed.
Q8.What are cookies, localStorage and sessionStorage?
Cookies are small values sent with every request to their domain and can be HttpOnly and Secure. localStorage keeps data in the browser with no expiry, sessionStorage only for the tab's lifetime. Neither storage API is sent to the server automatically.
Q9.What is a CDN?
A content delivery network caches files on servers around the world, so users download them from a nearby location. It cuts latency, absorbs traffic spikes and often adds DDoS protection and image optimisation.
Q10.What is the difference between HTTP/1.1, HTTP/2 and HTTP/3?
HTTP/1.1 handles one request at a time per connection. HTTP/2 multiplexes many requests over one TCP connection with header compression. HTTP/3 runs over QUIC on UDP, which avoids TCP head-of-line blocking and connects faster on mobile networks.
Q11.What is the difference between a static and a dynamic website?
A static site serves pre-built files, so it is fast and cheap to host. A dynamic site builds pages per request from a server and database, which suits logged-in or frequently changing content. Static site generators and caching blur the line.
Q12.What is the difference between a domain, hosting and a web server?
The domain is the name people type, registered through a registrar. Hosting is the machine or service where your files and code run. The web server, such as Nginx or Apache, is the software on that machine that answers HTTP requests.
Q13.What is caching in the browser and how do you control it?
The browser stores responses so it does not download them again. The server controls it with headers like Cache-Control: max-age=31536000, immutable for versioned assets and no-cache with ETags for HTML that must be checked on each visit.
HTML and CSS
Markup and styling questions.
Q14.What is semantic HTML and why does it matter?
Using elements for their meaning, such as header, nav, main, article, button and h1 to h6, instead of generic divs. It helps screen readers, search engines and other developers understand the page.
Q15.What is the purpose of the DOCTYPE?
<!DOCTYPE html> tells the browser to render in standards mode. Without it, browsers fall back to quirks mode with old, inconsistent behaviour.
Q16.What is the difference between block, inline and inline-block?
Block elements start on a new line and take the full width. Inline elements flow with text and ignore width and height. Inline-block flows inline but respects width, height and vertical padding.
Q17.Explain the CSS box model.
Every element is a box of content, padding, border and margin. With box-sizing: content-box, width covers only the content. With border-box, width includes padding and border, which makes layouts easier, so most resets apply it globally.
Q18.How does CSS specificity work?
Browsers pick the rule with the highest specificity: inline styles beat IDs, IDs beat classes, attributes and pseudo-classes, which beat element selectors. If equal, the later rule wins. !important overrides normal rules and should be rare.
Q19.What is the difference between Flexbox and Grid?
Flexbox is one-dimensional, laying out items in a row or a column. Grid is two-dimensional, controlling rows and columns together. Flexbox suits navbars and button groups; Grid suits page layouts and card grids.
Q20.What are the CSS position values?
static is the default, relative offsets from its normal place, absolute positions against the nearest positioned ancestor, fixed against the viewport, and sticky acts relative until a scroll threshold, then sticks.
Q21.How do you make a site responsive?
Start with the viewport meta tag, use fluid layouts with Flexbox and Grid, relative units like rem and percentages, media queries for breakpoints, container queries for components and responsive images with srcset and sizes.
Q22.What is the difference between em, rem, vh and vw?
em is relative to the parent's font size, rem to the root font size, vh and vw to 1 percent of the viewport height and width. Newer dvh units handle mobile browser toolbars better than vh.
Q23.How do you center an element horizontally and vertically?
On the parent use display: grid; place-items: center; or display: flex; justify-content: center; align-items: center;. For an absolutely positioned child, use inset 0 with margin auto or a transform.
Q24.What are CSS custom properties?
Variables declared like --brand: #C75101 and used with var(--brand). They cascade, can change at runtime and are the usual way to build themes such as dark mode.
Q25.What are pseudo-classes and pseudo-elements?
Pseudo-classes select elements in a state, such as :hover, :focus-visible or :nth-child(2). Pseudo-elements style a part of an element, such as ::before, ::after or ::placeholder.
Q26.Why should images have width and height attributes?
They let the browser reserve the right space before the image loads, which prevents layout shift and improves Cumulative Layout Shift. CSS can still make the image responsive with max-width: 100%; height: auto;.
Q27.How do forms work in HTML?
A form element sends its named inputs to the URL in its action attribute using GET or POST. Use the right input types such as email and number, labels linked with for and id, and built-in validation attributes like required and pattern, then validate again on the server.
JavaScript and APIs
Client-side scripting and data questions.
Q28.What is the difference between var, let and const?
var is function-scoped and hoisted with undefined. let and const are block-scoped and stay in the temporal dead zone until declared. const cannot be reassigned, though objects it points to can change.
Q29.What is the difference between == and ===?
== converts types before comparing, so '1' == 1 is true. === compares value and type without conversion. Use === by default.
Q30.What is the DOM?
The Document Object Model is a tree of objects that represents the page. JavaScript can read and change it to update content, styles and structure.
Q31.What is event delegation?
Attaching one listener to a parent instead of many children. Events bubble up, so the parent checks event.target to see which child was clicked. It saves memory and works for elements added later.
Q32.What is a Promise and how does async/await relate?
A Promise represents a value that will be available later, in a pending, fulfilled or rejected state. async/await is syntax on top of promises that lets you write asynchronous code that reads top to bottom, with try/catch for errors.
Q33.How do you call an API with fetch?
const res = await fetch(url), check res.ok because fetch does not reject on 404 or 500, then await res.json(). Send JSON with method POST, a Content-Type header and a stringified body.
Q34.What is JSON?
JavaScript Object Notation is a text format for data with objects, arrays, strings, numbers, booleans and null. It is the standard format for web APIs. Use JSON.parse and JSON.stringify to convert it.
Q35.What is CORS?
Cross-Origin Resource Sharing lets a server tell the browser which other origins may read its responses, using headers like Access-Control-Allow-Origin. Non-simple requests trigger a preflight OPTIONS request. CORS is enforced by browsers, not servers.
Q36.What is the difference between REST and GraphQL?
REST exposes many endpoints, each returning a fixed shape. GraphQL exposes one endpoint where the client asks for exactly the fields it needs, which avoids over-fetching but needs more server-side care with caching and query cost.
Q37.What is the difference between client-side and server-side rendering?
With client-side rendering the browser downloads JavaScript that builds the page, which can be slow on first load and harder for some crawlers. Server-side rendering sends ready HTML, then hydrates it. Frameworks like Next.js and Nuxt mix both with static generation.
Q38.What is a closure in JavaScript?
A function that remembers variables from the scope where it was created, even after that scope has finished. Closures power private state, event handlers and functions like debounce.
Q39.What is the difference between localStorage and a database?
localStorage lives in one user's browser, holds a few megabytes of strings and can be cleared at any time. A database lives on the server, is shared by all users and is the source of truth.
Security, SEO and deployment
Questions that check you can ship a site properly.
Q40.What is XSS and how do you prevent it?
Cross-site scripting injects malicious scripts into pages other users view. Prevent it by escaping output for its context, avoiding innerHTML with user data, sanitising rich text and setting a Content Security Policy.
Q41.What is CSRF and how do you prevent it?
Cross-site request forgery tricks a logged-in user's browser into sending an unwanted request. Defences include SameSite cookies, anti-CSRF tokens on state-changing forms and checking the Origin header.
Q42.What is SQL injection?
Untrusted input changes the meaning of a SQL query, for example logging in without a password. Always use parameterised queries or an ORM, never string concatenation.
Q43.How should passwords be stored?
Hashed with a slow, salted algorithm such as Argon2id or bcrypt, never encrypted or stored in plain text. Add rate limiting on login and support multi-factor authentication.
Q44.What are the basics of on-page SEO?
A unique title and meta description per page, one clear h1, logical headings, descriptive URLs, internal links, alt text on images, fast loading, mobile-friendly layout, canonical tags for duplicates and structured data where it fits.
Q45.What are Core Web Vitals?
Google's user experience metrics: Largest Contentful Paint for loading (good under 2.5 s), Interaction to Next Paint for responsiveness (good under 200 ms) and Cumulative Layout Shift for visual stability (good under 0.1).
Q46.How do you speed up a slow website?
Measure with Lighthouse and PageSpeed Insights, compress and resize images into WebP or AVIF, lazy-load below-the-fold media, minify and defer JavaScript, use caching and a CDN, reduce third-party scripts and improve server response time.
Q47.How do you deploy a website?
Static sites go to hosts like Netlify, Vercel or Cloudflare Pages from a Git push. Dynamic apps go to a VPS, a platform like Render or a cloud service, behind a web server such as Nginx, with environment variables for secrets, HTTPS certificates and a CI pipeline.
Q48.What is Git and why use branches?
Git is a distributed version control system. Branches let you work on a feature without affecting main, then merge through a pull request after review and tests.
Q49.How do you make a website accessible?
Use semantic HTML, label every form field, give images alt text, keep colour contrast at WCAG AA levels, make everything usable by keyboard with visible focus, and test with a screen reader and automated checks such as axe.
Q50.A client says the site is down. What do you check first?
Whether it is down for everyone, using a status checker. Then DNS and domain expiry, the SSL certificate, the hosting status page, server resources and error logs, and recent deployments or plugin updates that could be rolled back.
Q51.What is HTTPS mixed content?
An HTTPS page loading scripts, images or styles over HTTP. Browsers block active mixed content like scripts and warn about the rest. Fix it by serving every asset over HTTPS and updating hard-coded URLs.
Q52.What is the purpose of robots.txt and an XML sitemap?
robots.txt tells crawlers which paths not to crawl, but it does not remove pages from the index; noindex does that. An XML sitemap lists the URLs you want discovered, with last modified dates, and is submitted in Search Console.
How to prepare for the interview
- Keep a portfolio with two or three live projects and the code on GitHub.
- Be ready to build a small page live: a responsive card layout, a form with validation or a fetch call to an API.
- Explain what happens when you type a URL; it is still the most common opener.
- Know the basics of Git: branching, merging, resolving conflicts and pull requests.