Basic JavaScript questions
1. What is the difference between var, let and const?
var is function-scoped, hoisted and initialised as undefined. let and const are block-scoped and stay in the temporal dead zone until declared. const cannot be reassigned, although an object it points to can still be mutated.
2. What is the difference between == and ===?
== compares after type coercion, so 0 == '0' is true. === compares value and type without coercion and is the recommended default.
3. What is hoisting?
Declarations are processed before code runs. Function declarations are hoisted with their body, var declarations are hoisted and set to undefined, and let, const and class are hoisted but cannot be used before their declaration line.
Intermediate JavaScript questions
4. What is a closure?
A closure is a function that remembers the variables of the scope where it was created, even after that outer function has returned. Closures power data privacy, function factories, memoization and callbacks.
5. Explain the event loop.
JavaScript runs on one thread with a call stack. Async callbacks wait in queues: after each task the engine drains the microtask queue (promise callbacks, queueMicrotask) before taking the next macrotask (setTimeout, I/O, events). That is why a resolved promise callback runs before a setTimeout of 0.
6. How does this work in JavaScript?
this depends on how a function is called: the object before the dot for methods, undefined in strict-mode plain calls, the new instance with new, and the value passed to call, apply or bind. Arrow functions do not have their own this; they use the surrounding scope's.
7. Promise.all vs Promise.allSettled vs Promise.race?
Promise.all resolves with all results or rejects on the first failure. Promise.allSettled waits for every promise and reports each status. Promise.race settles with the first promise that settles, and Promise.any resolves with the first success.
8. What is event delegation?
Instead of adding listeners to many child elements, add one listener to a parent and use event.target to find which child was clicked. It relies on event bubbling, saves memory and works for elements added later.
Advanced JavaScript questions
9. What is the difference between debounce and throttle?
Debounce runs a function only after events stop for a set time (search box typing). Throttle runs it at most once per interval while events keep firing (scroll or resize handlers).
10. How does prototypal inheritance work?
Every object has an internal [[Prototype]] link. When a property is missing, JavaScript looks it up along the prototype chain. class syntax is sugar over constructor functions and prototypes.
Want to practise these with a trainer? APEX live batches include mock interviews, real projects and placement support. See upcoming batches.
