JavaScript Interview Prep Summary
1. JavaScript Loops Summary (map, filter, forEach)
| Method | Return Karta Hai? | Kya Karta Hai | Common Use-case |
|------------|-------------------|----------------------------------------|---------------------------|
| .map() | Yes | Har item ko transform karta hai | UI render in React |
| .filter() | Yes | Sirf matching elements nikalta hai | List filtering, search |
| .forEach() | No | Har item pe kaam karta hai (side-effect)| Console.log, API call
Syntaxes:
.map(): array.map((item, index) => { return updatedItem; });
.filter(): array.filter((item, index) => { return condition; });
.forEach(): array.forEach((item, index) => { /* action */ });
2. Arrow Function Syntax (React Style)
const functionName = (params) => {
// logic
};
Single-line (implicit return):
const square = n => n * n;
No parameter:
const sayHi = () => console.log("Hi!");
3. What is DOM?
DOM (Document Object Model) is a JavaScript-based representation of the HTML structure of a web page.
It allows JavaScript to interact with and manipulate HTML and CSS.
JavaScript Interview Prep Summary
Example:
document.querySelector("h1").innerText = "Changed Heading";
Key Functions:
- document.querySelector()
- getElementById()
- innerText / innerHTML
- addEventListener()
Use-case: Modify content, handle events, dynamic rendering, etc.
4. Promises and Async/Await Syntax
Definition:
"A Promise in JavaScript is an object that represents the eventual completion (or failure) of an asynchronous
operation and its resulting value.
It provides a cleaner alternative to callback-based handling through .then() and .catch() methods."
3 States: pending, fulfilled, rejected
Async/Await (React-style arrow function):
const fetchData = async () => {
try {
const res = await fetch("https://api.example.com/data");
const data = await res.json();
console.log(data);
} catch (err) {
console.log("Error:", err);
}
JavaScript Interview Prep Summary
};
5. Most Asked JavaScript Interview Questions
1. What is JavaScript?
2. Difference between var, let, and const?
3. What is hoisting?
4. What is closure?
5. What is the difference between == and ===?
6. What are Promises and how do they work?
7. What is async/await? Why use them?
8. What is the DOM?
9. Difference between map, filter, forEach?
10. How does event delegation work?