JavaScript Interview Questions & Answers – Part 2: DOM, Types & Advanced Topics
Continue your JavaScript interview preparation with Part 2 of our Q&A series. This set of 25 curated questions dives into DOM & Browser APIs, JavaScript types and coercion, advanced concepts like closures and hoisting, and various miscellaneous topics to help you build deeper understanding and tackle tricky interview problems.
📦 DOM & Browser APIs
- 1. What is the DOM? Document Object Model – tree representation of HTML
- 2. How to select DOM elements?
document.getElementById("id"), querySelector(".class")
- 3. How to add/remove event listeners?
element.addEventListener('click', handler);
- 4. What is event delegation? Event handling at parent level to reduce listeners.
- 5. What are localStorage and sessionStorage? Store key-value data in browser; localStorage persists, sessionStorage clears on close.
🧪 Types & Coercion
- 6. What is type coercion? JS automatically converts types when needed (e.g., '5' + 1 → '51')
- 7. How to check the type of a variable?
typeof variable
- 8. How to convert a string to a number?
Number("5"), parseInt("5"), +"5"
- 9. Falsy values in JavaScript? false, 0, "", null, undefined, NaN,
- 10. What is NaN? “Not a Number” – result of invalid numeric operations.
🛠️ Advanced Topics
- 11. What is a generator function?
function* gen() { yield 1; yield 2; }
- 12. What are modules in JS?
export const a = 5; import {a} from './file';
- 13. Difference between deep freeze and shallow freeze? Object.freeze makes top-level immutable; not nested objects.
- 14. What is memoization? Caching results of function calls to optimize performance.
- 15. What are higher-order functions? Functions that take or return other functions.
📚 Miscellaneous
- 16. What is debouncing and throttling? Debounce: delays function until inactivity
Throttle: limits function execution rate - 17. What is the difference between map, filter, and reduce?map transforms, filter selects, reduce accumulates
- 18. What is JSON and how do you parse it?
JSON.parse(jsonStr), JSON.stringify(obj)
- 19. What is the difference between forEach and map?map returns new array, forEach doesn’t.
- 20.What is the Temporal Dead Zone (TDZ)?Time between declaration and initialization of let / const where accessing it throws error.
- 21. What is optional chaining (?.)
let name = user?.profile?.name;
- 22. What are template literals?
`Hello ${name}`
- 23.What is the difference between Array.of() and Array()?Array.of(3) creates [3], Array(3) creates empty of length 3.
- 24. What is a symbol in JavaScript? A unique, immutable primitive used as object keys.
- 25. What is the use of Object.keys(), Object.values(),Object.entries() ?
Object.keys(obj) // ['a'] Object.values(obj) // [1] Object.entries(obj) // [['a', 1]]