Security
XSS, CSP, CSRF, auth token storage, supply chain and third-party script risks.
1.What are some common security headers and their purpose?
CSP, HSTS, X-Content-Type-Options, Referrer-Policy, Permissions-Policy, COOP and friends.
2.What are some best practices for handling sensitive data in JavaScript?
What never belongs in the client, token storage, transport, logging and memory hygiene.
3.Do TypeScript types exist at runtime? How do you validate external data?
Type erasure, trust boundaries, schema validation and type stripping.
4.Explain stored, reflected and DOM-based XSS. Does using React make you safe?
The three XSS classes, what JSX escaping does and doesn't cover, and defence in depth.
5.Embeddable Poll Widget
Design a poll widget embeddable on many sites, with voting, live results, abuse prevention and isolation.
6.How would you design and roll out a Content Security Policy for an existing production app?
Strict nonce-based CSP, strict-dynamic, report-only rollout, reporting, and the directives that matter.
7.What are the most common misconceptions about CORS as a security mechanism?
Why CORS relaxes rather than adds protection, origin reflection bugs, null origins and what actually protects APIs.
8.What is CSRF, and is SameSite=Lax enough to prevent it in 2025?
How CSRF works, SameSite modes and browser defaults, same-site vs same-origin, and layered defences.
9.How can you implement secure authentication and authorization in JavaScript applications?
Session cookies vs tokens, OAuth/OIDC with PKCE, passkeys, and server-enforced authorization.
10.Where should a browser app store JWTs or session tokens: localStorage, memory or cookies?
XSS vs CSRF exposure, HttpOnly cookies, in-memory access tokens with refresh rotation, and the BFF pattern.
11.E-commerce Marketplace (e.g. Amazon)
Design the front end of a large e-commerce site: search and listing, product detail, cart and checkout, with SEO and Core Web Vitals in mind.
12.Email Client (e.g. Outlook / Gmail)
Design a web email client: folders and threaded inbox, safe rendering of HTML emails, composer with drafts, offline and keyboard-driven workflows.
13.Rich Text Editor Component
Design a reusable rich text editor: document model vs contenteditable, transactions, plugins, paste, IME and accessibility.
14.How do you add, remove, and modify HTML elements using JavaScript?
createElement, append, replaceWith, remove, classList, fragments, templates and avoiding innerHTML XSS.
15.How do you redirect to a new page in JavaScript?
location.assign vs replace, router navigation, server redirects and open-redirect safety.
16.Deep Merge
Recursively merge configuration objects without mutating the inputs, with clear rules for arrays and undefined.
17.Set
Write a value at a nested path, creating missing objects and arrays along the way.
18.Template Engine
Build a {{ }} interpolation engine with dotted paths, HTML escaping, raw {{{ }}} output, filters and a compile step.
19.What is clickjacking, and how do you defend against it?
UI redressing via invisible iframes, frame-ancestors vs X-Frame-Options, and legitimate embedding.
20.How do iframes on a page communicate?
Cross-origin messaging with postMessage, origin checks and MessageChannel.
21.What is the difference between innerHTML and textContent?
How markup parsing, text nodes and innerText differ, and why textContent is the safe default.
22.Explain the concept of input validation and its importance in security
Server-side allowlist validation with schemas, versus output encoding, and why client checks are UX only.
23.What are some tools and techniques for identifying security vulnerabilities in JavaScript code?
Dependency audits, SAST, secret scanning, DAST, CSP reporting and code review in CI.
24.How can you prevent SQL injection vulnerabilities in JavaScript applications?
Parameterized queries, ORMs, query builders and least privilege on the Node.js side.
25.What is Subresource Integrity (SRI), and how do you manage the risk of third-party scripts?
Integrity hashes, crossorigin, why SRI doesn't fit evergreen tags, and isolation strategies for third parties.
26.Image Uploader Component
Design a multi-file image uploader with previews, client-side resizing, resumable direct-to-storage uploads and progress.
27.How do you safely embed untrusted content with iframe sandboxing?
sandbox tokens, the allow-scripts + allow-same-origin trap, separate origins, allow (Permissions Policy) and srcdoc.
28.How do you reduce supply-chain risk from npm dependencies in a front-end codebase?
Typosquatting, compromised maintainers, install scripts, lockfiles, provenance and dependency governance.