21. What is the event loop in JS?
The event loop manages execution of tasks (callbacks, promises) in JavaScript. It continuously checks the call stack and task queues, executing code in a non-blocking way — enabling asynchronous behavior. 🔄
22. Explain microtask vs. macrotask queue
- Microtasks: Promise callbacks,
queueMicrotask, MutationObserver — run immediately after the current operation finishes. ⚡- Macrotasks:
setTimeout, setInterval, I/O — run after microtasks are done. ⏳23. What is JSON and how is it used?
JSON (JavaScript Object Notation) is a lightweight data-interchange format used to store and exchange data. 📁
const obj = { name: "Alex" };
const str = JSON.stringify(obj); // convert to JSON string
const newObj = JSON.parse(str); // convert back to object24. What are IIFEs (Immediately Invoked Function Expressions)?
Functions that execute immediately after being defined. 🚀
(function() {
console.log("Runs instantly!");
})();25. What is the difference between synchronous and asynchronous code?
- Synchronous: Runs in order, blocking the next line until the current finishes. 🛑
- Asynchronous: Doesn’t block, allows other code to run while waiting (e.g.,
fetch calls, setTimeout). ✅26. How does JavaScript handle memory management?
JS uses automatic garbage collection — it frees up memory by removing unused objects. Developers must avoid memory leaks by cleaning up listeners, intervals, and unused references. ♻️
27. What is a JavaScript engine?
A JS engine (like V8 in Chrome/Node.js) is a program that parses, compiles, and executes JavaScript code. ⚙️
28. Difference between deep copy and shallow copy in JS
- Shallow copy: Copies references for nested objects. Changes in nested objects affect both copies. 🤝
- Deep copy: Creates a complete, independent copy of all nested objects. 👯
const original = { a: 1, b: { c: 2 } };
const shallow = { ...original }; // { a: 1, b: { c: 2 } } - b still references original.b
const deep = JSON.parse(JSON.stringify(original)); // { a: 1, b: { c: 2 } } - b is a new object29. What is destructuring in ES6?
A convenient way to unpack values from arrays or properties from objects into distinct variables. ✨
const [a, b] = [1, 2]; // a=1, b=2
const {name} = { name: "John", age: 25 }; // name="John"
30. What is a spread operator (...) in ES6?
The spread operator allows an iterable (like an array or string) to be expanded in places where zero or more arguments or elements are expected, or an object expression to be expanded in places where zero or more key-value pairs are expected. 🥞
const nums = [1, 2];
const newNums = [...nums, 3]; // [1, 2, 3]
const obj1 = { a: 1 };
const obj2 = { ...obj1, b: 2 }; // { a: 1, b: 2 }
💬 Double Tap ❤️ For Part-4!
#JavaScript #JSInterview #CodingInterview #Programming #WebDevelopment #Developer #AsyncJS #ES6