Model answers for 4 JavaScript questions
Typical round: concepts, output-prediction questions, a small coding task
Q: What is a closure? A: A function that remembers variables from the scope where it was created, even after that scope has finished. For example, a counter function returned from makeCounter() keeps its own count variable between calls. Closures power data privacy, callbacks and hooks.
Q: How does the event loop work? A: JavaScript runs one call stack. Async callbacks wait in queues. When the stack is empty, the event loop runs all microtasks first, like promise callbacks, then takes the next macrotask, like a setTimeout callback. That's why a resolved promise logs before setTimeout(fn, 0).
Q: What is the difference between var, let and const? A: var is function-scoped and hoisted with undefined. let and const are block-scoped and sit in the temporal dead zone until declared. const prevents reassignment, but objects declared with const can still be mutated.
Q: What does this refer to? A: It depends on how a function is called: the object before the dot for method calls, undefined in strict-mode plain calls, the new instance with new, and whatever bind, call or apply sets. Arrow functions don't have their own this; they use the surrounding one.