Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: Use the prefers-color-scheme media query or toggle themes via classes. Example (automatic via system theme): Follow me on LinkedIn: @media (prefers-color-scheme: dark) { body { background: #121212; color: #…
Short answer: Feature Flexbox Grid Layout One-dimensional (row or column) Two-dimensional (rows and columns) Use Case Aligning items in a line Building full-page layouts Alignment Easier for single direction Easier for f…
Short answer: Element selector: Targets HTML tags. p { color: green; } Element selector: Targets HTML tags. p { color: green; } Element selector: Targets HTML tags. p { color: green; } Element selector: Targets HTML tags…
Short answer: Use classes for reusable styles, IDs for unique elements. Real-world example (ShopNest) ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling. Say th…
Short answer: Example: <user-card></user-card> <template id="user-template"> <p>Hello, <span id="name"></span></p> </template> <script> class User…
Short answer: The Shadow DOM is a web component feature that encapsulates a section of the DOM — meaning styles and markup inside it don’t leak out or get affected by the rest of the page. Example: <custom-card><…
Short answer: DOM + CSSOM = Render Tree (a visual structure of elements and styles). Real-world example (ShopNest) ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error han…
Short answer: The <canvas> element is used to draw graphics, animations, charts, or games using JavaScript. Example: <canvas id="myCanvas" width="200" height="100"></canvas>…
Short answer: Tags define the structure and content (e.g., <p>, <h1>, <div>). Attributes provide additional details about an element (e.g., src, href, alt). Follow me on LinkedIn: Example code <img s…
Short answer: Primitive types: string, number, boolean, null, undefined, symbol, bigint Reference types: object, array, function Example code let name = "Sandeep"; let obj = { age: 30 }; Real-world example (Sho…
Short answer: pply () Same as call(), but takes array Array ✅ Yes bind( Returns a new function with fixed this Comma-separat ed ❌ No function greet(greeting) { console.log(`${greeting}, ${this.name}`); } const user = { n…
Short answer: A container wraps page content and provides horizontal padding. <div class="container">Content</div> <div class="container-fluid">Full width</div> Real-world exam…
Short answer: A service worker is a background script that runs independently of the web page. It enables offline caching, push notifications, and background sync. Example code navigator.serviceWorker.register('/sw.js');…
Short answer: ✅ Result: lightning-fast execution of JS. Real-world example (ShopNest) ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling. Say this in the interv…
Short answer: Metho Purpose Arguments Invokes Immediately? call( Call a function with a specific this Comma-separat ed ✅ Yes apply () Same as call(), but takes array Array ✅ Yes bind( Returns a new function with fixed th…
Short answer: Preprocessors extend CSS with variables, nesting, mixins, and functions, compiled into plain CSS. Example (SASS): $main-color: #3498db; .button { background: $main-color; &:hover { background: darken($m…
Short answer: Use fractional units (fr) and media queries. Example code .container { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 10px; } Key Takeaway: auto-fit and minmax() automatica…
Short answer: Type Scope Example Priority Inline Single element style="color:re d;" Highest Internal One page <style> inside <head> Medium External Multiple pages Linked .css file Lowest Key Takeawa…
Short answer: SEO optimization starts with clean, structured, and semantic HTML. Best practices: Follow me on LinkedIn: Use meaningful tags (<header>, <article>, <footer>). Add <title>, <meta n…
Short answer: The browser calculates positions (layout) and then paints pixels on the screen. Key Takeaway: The DOM is built first, then styles are applied, and finally pixels are rendered — optimizing this pipeline impr…
Short answer: Both store data in the browser, but they differ in duration and scope. Feature localStorage sessionStorage Lifetime Until manually cleared Until the tab is closed Scope Shared across tabs Specific to one ta…
Short answer: <div> is a block-level element (creates a full-width container). <span> is an inline element (used for styling small text portions). Example code <div>Block Section</div> <p>Th…
Short answer: Variables are containers to store data. let age = 25; Variables are containers to store data. Example code let age = 25; Variables are containers to store data. Example: let age = 25; Variables are containe…
Short answer: A Promise represents a value that may be available now, later, or never. It helps handle asynchronous operations in a cleaner way. Follow me on LinkedIn: Example code fetch('/data') .then(res => res.json…
Short answer: Bootstrap uses a 12-column grid based on flexbox. You divide your layout using .row and .col-* classes. Follow me on LinkedIn: <div class="row"> <div class="col-6">Half</d…
JavaScript JavaScript Tutorial · JavaScript
Short answer: Use the prefers-color-scheme media query or toggle themes via classes. Example (automatic via system theme): Follow me on LinkedIn: @media (prefers-color-scheme: dark) { body { background: #121212; color: #fff; }
} Example (manual toggle): body.dark-mode { background: #000; color: white; } Key Takeaway: Dark mode can adapt automatically or via user preference toggles.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Feature Flexbox Grid Layout One-dimensional (row or column) Two-dimensional (rows and columns) Use Case Aligning items in a line Building full-page layouts Alignment Easier for single direction Easier for full layout structure
/* Flexbox */ display: flex; /* Grid */ Follow me on LinkedIn: display: grid; grid-template-columns: repeat(3, 1fr); Key Takeaway: Use Flexbox for alignment; Grid for complete layouts.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Element selector: Targets HTML tags. p { color: green; } Element selector: Targets HTML tags. p { color: green; } Element selector: Targets HTML tags. p { color: green; } Element selector: Targets HTML tags. p { color: green; }
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Use classes for reusable styles, IDs for unique elements.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Example: <user-card></user-card> <template id="user-template"> <p>Hello, <span id="name"></span></p> </template> <script> class UserCard extends HTMLElement { connectedCallback() { const tmpl = document.getElementById("user-template");
const content = tmpl.content.cloneNode(true);
content.querySelector("#name").textContent = "Sandeep"; this.appendChild(content); }
} customElements.define("user-card", UserCard); </script> Key Takeaway: Web Components = reusable, encapsulated building blocks for modern web apps.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: The Shadow DOM is a web component feature that encapsulates a section of the DOM — meaning styles and markup inside it don’t leak out or get affected by the rest of the page. Example: <custom-card></custom-card> <script> class CustomCard extends HTMLElement { constructor() { super(); const shadow = this.attachShadow({ mode: 'open' });
shadow.innerHTML = `<style>p { color: blue; }</style><p>Hello Shadow!</p>`; }
} customElements.define('custom-card', CustomCard); </script> Key Takeaway: Shadow DOM = style and structure isolation for reusable, predictable components.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: DOM + CSSOM = Render Tree (a visual structure of elements and styles).
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: The <canvas> element is used to draw graphics, animations, charts, or games using JavaScript. Example: <canvas id="myCanvas" width="200" height="100"></canvas> <script> const canvas = document.getElementById("myCanvas"); ctx.fillStyle = "blue"; ctx.fillRect(10, 10, 180, 80); </script> Follow me on LinkedIn: Key Takeaway: <canvas> gives you a pixel-based drawing area inside HTML — perfect for dynamic graphics.
const ctx = canvas.getContext("2d");
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Tags define the structure and content (e.g., <p>, <h1>, <div>). Attributes provide additional details about an element (e.g., src, href, alt). Follow me on LinkedIn:
<img src="logo.png" alt="Company Logo"> Here, <img> is a tag, and src & alt are attributes. Key Takeaway: Tags = structure; Attributes = extra information.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Primitive types: string, number, boolean, null, undefined, symbol, bigint Reference types: object, array, function
let name = "Sandeep"; let obj = { age: 30 };
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: pply () Same as call(), but takes array Array ✅ Yes bind( Returns a new function with fixed this Comma-separat ed ❌ No function greet(greeting) { console.log(`${greeting}, ${this.name}`); } const user = { name: "John" }; greet.call(user, "Hi"); greet.apply(user, ["Hello"]); const bound = greet.bind(user, "Hey"); bound(); … pply () Same as call(),… but takes array Array ✅ Yes bind( Returns a new function with fixed…
function greet(greeting) { console.log(`${greeting}, ${this.name}`); } const user = { name: "John" }; greet.call(user, "Hi"); greet.apply(user, ["Hello"]); const bound = greet.bind(user, "Hey"); bound(); pply () Same as call(), but takes array Array ✅ Yes bind( Returns a new function with fixed this Comma-separat ed ❌ No Example: function greet(greeting) { console.log(`${greeting}, ${this.name}`); } const user = { name: "John" }; greet.call(user, "Hi"); greet.apply(user, ["Hello"]); const bound = greet.bind(user, "Hey"); bound(); … pply () Same as call(), but takes array Array ✅ Yes bind( Returns a new function with fixed this Comma-separat ed ❌ No Example: function greet(greeting) { console.log(`${greeting}, ${this.name}`); } const user = { name: "John" }; greet.call(user, "Hi"); greet.apply(user, ["Hello"]); const bound = greet.bind(user, "Hey"); bound();
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: A container wraps page content and provides horizontal padding. <div class="container">Content</div> <div class="container-fluid">Full width</div>
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: A service worker is a background script that runs independently of the web page. It enables offline caching, push notifications, and background sync.
navigator.serviceWorker.register('/sw.js'); ✅ Used in Progressive Web Apps (PWAs).
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: ✅ Result: lightning-fast execution of JS.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Metho Purpose Arguments Invokes Immediately? call( Call a function with a specific this Comma-separat ed ✅ Yes apply () Same as call(), but takes array Array ✅ Yes bind( Returns a new function with fixed this Comma-separat ed ❌ No Example: function greet(greeting) { console.log(`${greeting}, ${this.name}`); }
const user = { name: "John" }; greet.call(user, "Hi"); greet.apply(user, ["Hello"]); const bound = greet.bind(user, "Hey"); bound();
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Preprocessors extend CSS with variables, nesting, mixins, and functions, compiled into plain CSS. Example (SASS): $main-color: #3498db; .button { background: $main-color; &:hover { background: darken($main-color, 10%); } } Key Takeaway: Preprocessors make CSS more modular, maintainable, and reusable.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Use fractional units (fr) and media queries.
.container { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 10px; } Key Takeaway: auto-fit and minmax() automatically adapt the grid to screen size.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Type Scope Example Priority Inline Single element style="color:re d;" Highest Internal One page <style> inside <head> Medium External Multiple pages Linked .css file Lowest Key Takeaway: Use external CSS for maintainable, large-scale projects. Follow me on LinkedIn:
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: SEO optimization starts with clean, structured, and semantic HTML. Best practices: Follow me on LinkedIn: Use meaningful tags (<header>, <article>, <footer>). Add <title>, <meta name="description">, and proper heading hierarchy (<h1> → <h6>). Use descriptive alt text for images. Ensure mobile-friendly and fast-loading pages. Include internal linking and structured data.
<meta name="description" content="Learn web development step-by-step with examples."> <h1>HTML Interview Questions</h1> Key Takeaway: SEO-friendly HTML = clear structure + accurate metadata + accessible content.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: The browser calculates positions (layout) and then paints pixels on the screen. Key Takeaway: The DOM is built first, then styles are applied, and finally pixels are rendered — optimizing this pipeline improves page performance.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Both store data in the browser, but they differ in duration and scope. Feature localStorage sessionStorage Lifetime Until manually cleared Until the tab is closed Scope Shared across tabs Specific to one tab Capacity ~5–10MB ~5MB
localStorage.setItem("username", "Sandeep"); sessionStorage.setItem("theme", "dark"); Key Takeaway: Use localStorage for long-term data; sessionStorage for temporary, tab-specific data.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: <div> is a block-level element (creates a full-width container). <span> is an inline element (used for styling small text portions).
<div>Block Section</div> <p>This is a <span style="color: red;">red word</span> in a sentence.</p> Key Takeaway: Use <div> for layout; <span> for inline styling.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Variables are containers to store data. let age = 25; Variables are containers to store data.
let age = 25; Variables are containers to store data. Example: let age = 25; Variables are containers to store data. Example: let age = 25;
In ShopNest’s cart UI, a click handler closes over productId. Use let in loops so each button keeps the correct id.
JavaScript JavaScript Tutorial · JavaScript
Short answer: A Promise represents a value that may be available now, later, or never. It helps handle asynchronous operations in a cleaner way. Follow me on LinkedIn:
fetch('/data') .then(res => res.json()) .then(data => console.log(data)) .catch(err => console.error(err)); ✅ async/await simplifies promise syntax.
The checkout button uses async/await to call /api/orders, shows a spinner, and catches network errors with a toast.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Bootstrap uses a 12-column grid based on flexbox. You divide your layout using .row and .col-* classes. Follow me on LinkedIn: <div class="row"> <div class="col-6">Half</div> <div class="col-6">Half</div> </div>
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.