Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: The constructor is a special method for initializing new objects created from a class. Example: class Car { constructor(brand, model) { this.brand = brand; this.model = model; } } Example code The construct…
Short answer: Feature Function Constructor Class Syntax function Person(){} class Person{} Hoisting Yes, function declarations are hoisted No, classes are not hoisted new required Recommended Required Real-world example…
Short answer: Classes support extends to create a subclass that inherits properties and methods from a parent class. Example: class Animal { speak() { console.log("Animal speaks"); } } class Dog extends Animal…
Short answer: super() calls the parent class constructor. Must be called before using this in subclass. Example: class Animal { Example code constructor(name) { this.name = name; } } class Dog extends Animal { constructo…
Short answer: Static methods are called on the class itself, not on instances. Example code class MathUtils { static square(x) { return x * x; } } console.log(MathUtils.square(5)); // 25 Real-world example (ShopNest) Sho…
Short answer: Yes, getters and setters control access to object properties. Example: class Person { Example code constructor(name) { this._name = name; } get name() { return this._name; } set name(value) { this._name = v…
Short answer: Allows non-blocking execution, letting other code run while waiting for tasks (e.g., network requests). Say this in the interview Define — one clear sentence (the short answer above). Example — relate it to…
Short answer: Functions passed as arguments to run after another function completes. Example: setTimeout(() => console.log("Hello after 1s"), 1000); Example code Functions passed as arguments to run after an…
Short answer: Nested callbacks causing hard-to-read code. Solution: Use Promises or async/await. Real-world example (ShopNest) ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and cle…
Short answer: n object representing future completion or failure of an async task. Real-world example (ShopNest) The checkout button uses async/await to call /api/orders , shows a spinner, and catches network errors with…
Short answer: pending fulfilled rejected Real-world example (ShopNest) The checkout button uses async/await to call /api/orders , shows a spinner, and catches network errors with a toast. Say this in the interview Define…
Short answer: fetch('/api/data') .then(res => res.json()) .then(data => console.log(data)) .catch(err => console.error(err)); Example code fetch('/api/data') .then(res => res.json()) .then(data => console.…
Short answer: sync function fetchData() { try { const res = await fetch('/api/data'); const data = await res.json(); console.log(data); } catch (err) { console.error(err); } } sync function fetchData() { try { const res…
Short answer: Syntactic sugar over Promises for cleaner asynchronous code. async function fetchData() { try { const res = await fetch('/api/data'); const data = await res.json(); console.log(data); } catch (err) { consol…
Short answer: Promise.all – waits for all promises to resolve Promise.race – resolves/rejects as soon as one completes Real-world example (ShopNest) The checkout button uses async/await to call /api/orders , shows a spin…
Short answer: Mechanism that manages async callbacks and executes them after the call stack is empty. Real-world example (ShopNest) The checkout button uses async/await to call /api/orders , shows a spinner, and catches…
Short answer: Call stack: executes synchronous code Microtask queue: handles Promises Macrotask queue: handles setTimeout, I/O, etc. Real-world example (ShopNest) ShopNest’s browser cart uses modern JavaScript: fetch API…
Short answer: n action like click, load, input, keypress. 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 inte…
Short answer: button.addEventListener('click', () => console.log('Clicked!')); button.addEventListener('click', () => console.log('Clicked!')); button.addEventListener('click', () => console.log('Clicked!')); bu…
Short answer: ttach a listener to a parent to handle events on child elements. Real-world example (ShopNest) ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.…
Short answer: preventDefault() – stops default browser action stopPropagation() – stops event bubbling Real-world example (ShopNest) ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, a…
Short answer: Catching and managing runtime errors to prevent app crashes. Explain a bit more Catching and managing runtime errors to prevent app crashes. Catching and managing runtime errors to prevent app crashes. Catc…
Short answer: Blocks to handle exceptions. try { JSON.parse("invalid"); } catch(e) { console.error(e); } Example code Blocks to handle exceptions. try { JSON.parse("invalid"); } catch(e) { console.err…
Short answer: Runs always, whether error occurs or not. 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: class ValidationError extends Error { } throw new ValidationError("Invalid input"); Example code class ValidationError extends Error { } throw new ValidationError("Invalid input"); Real-…
JavaScript JavaScript Tutorial · JavaScript
Short answer: The constructor is a special method for initializing new objects created from a class. Example: class Car { constructor(brand, model) { this.brand = brand; this.model = model; } }
The constructor is a special method for initializing new objects created from a class. Example: class Car { constructor(brand, model) { this.brand = brand;
this.model = model;
}
}
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: Feature Function Constructor Class Syntax function Person(){} class Person{} Hoisting Yes, function declarations are hoisted No, classes are not hoisted new required Recommended Required
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: Classes support extends to create a subclass that inherits properties and methods from a parent class. Example: class Animal { speak() { console.log("Animal speaks"); } } class Dog extends Animal { speak() { console.log("Dog barks"); } } const dog = new Dog(); dog.speak(); // Dog barks
Classes support extends to create a subclass that inherits properties and methods from a parent class. Example: class Animal { speak() { console.log("Animal speaks"); } }
class Dog extends Animal { speak() { console.log("Dog barks"); } }
const dog = new Dog(); dog.speak(); // Dog barks
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: super() calls the parent class constructor. Must be called before using this in subclass. Example: class Animal {
constructor(name) { this.name = name; }
}
class Dog extends Animal { constructor(name, breed) { super(name); this.breed = breed;
}
}
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Static methods are called on the class itself, not on instances.
class MathUtils { static square(x) { return x * x; } } console.log(MathUtils.square(5)); // 25
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Yes, getters and setters control access to object properties. Example: class Person {
constructor(name) { this._name = name; } get name() { return this._name; } set name(value) { this._name = value; }
}
const p = new Person("Sandeep"); console.log(p.name); // Sandeep p.name = "Ravi"; console.log(p.name); // Ravi
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Allows non-blocking execution, letting other code run while waiting for tasks (e.g., network requests).
JavaScript JavaScript Tutorial · JavaScript
Short answer: Functions passed as arguments to run after another function completes. Example: setTimeout(() => console.log("Hello after 1s"), 1000);
Functions passed as arguments to run after another function completes. Example: setTimeout(() => console.log("Hello after 1s"), 1000);
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Nested callbacks causing hard-to-read code. Solution: Use Promises or async/await.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: n object representing future completion or failure of an async task.
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: pending fulfilled rejected
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: fetch('/api/data') .then(res => res.json()) .then(data => console.log(data)) .catch(err => console.error(err));
fetch('/api/data') .then(res => res.json()) .then(data => console.log(data)) .catch(err => console.error(err));
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: sync function fetchData() { try { const res = await fetch('/api/data'); const data = await res.json(); console.log(data); } catch (err) { console.error(err); } } sync function fetchData() { try { const res = await fetch('/api/data'); const data = await res.json(); console.log(data); } catch (err) { console.error(err); } }… sync function fetchData() { try {… const res = await fetch('/api/data'); const data = await…
res.json(); console.log(data); } catch (err) { console.error(err); } } sync function fetchData() { try { const res = await fetch('/api/data'); const data = await res.json(); console.log(data); } catch (err) { console.error(err); } }…
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: Syntactic sugar over Promises for cleaner asynchronous code. async function fetchData() { try { const res = await fetch('/api/data'); const data = await res.json(); console.log(data); } catch (err) { console.error(err); } }
Syntactic sugar over Promises for cleaner asynchronous code. async function fetchData() { try { const res = await fetch('/api/data');
const data = await res.json(); console.log(data); } catch (err) { console.error(err); } }
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: Promise.all – waits for all promises to resolve Promise.race – resolves/rejects as soon as one completes
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: Mechanism that manages async callbacks and executes them after the call stack is empty.
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: Call stack: executes synchronous code Microtask queue: handles Promises Macrotask queue: handles setTimeout, I/O, etc.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: n action like click, load, input, keypress.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: button.addEventListener('click', () => console.log('Clicked!')); button.addEventListener('click', () => console.log('Clicked!')); button.addEventListener('click', () => console.log('Clicked!')); button.addEventListener('click', () => console.log('Clicked!'));
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: ttach a listener to a parent to handle events on child elements.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: preventDefault() – stops default browser action stopPropagation() – stops event bubbling
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Catching and managing runtime errors to prevent app crashes.
Catching and managing runtime errors to prevent app crashes. Catching and managing runtime errors to prevent app crashes. Catching and managing runtime errors to prevent app crashes. Catching and managing runtime errors to prevent app crashes. Catching and managing runtime errors to prevent app crashes. Catching and managing runtime errors to prevent app crashes. Catching and managing runtime errors to prevent app crashes.
Catching and managing runtime errors to prevent app crashes. Catching and managing runtime errors to prevent app crashes. Catching and managing runtime errors to prevent app crashes. Catching and managing runtime errors to prevent app crashes. Catching and managing runtime errors to prevent app crashes. Catching and managing runtime errors to prevent app crashes. Catching and managing runtime errors to prevent app crashes. Catching and managing runtime errors to prevent app crashes.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Blocks to handle exceptions. try { JSON.parse("invalid"); } catch(e) { console.error(e); }
Blocks to handle exceptions. try { JSON.parse("invalid"); } catch(e) { console.error(e); }
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: Runs always, whether error occurs or not.
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
JavaScript JavaScript Tutorial · JavaScript
Short answer: class ValidationError extends Error { } throw new ValidationError("Invalid input");
class ValidationError extends Error { } throw new ValidationError("Invalid input");
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.