Frontend · Fresher-relevant
Core JavaScript interview questions covering closures, async/await, prototypes, and ES6+ features tested at every Indian tech company.
Explain closures with a practical example.
Tip: A closure is a function that retains access to its lexical scope even after the outer function has returned. Practical uses: data privacy (module pattern), function factories, and memoisation. Example: a counter() returning an inner function that increments a captured variable.
What is the difference between var, let, and const?
Tip: var is function-scoped and hoisted (initialised undefined); let and const are block-scoped with a temporal dead zone before declaration. const prevents reassignment of the binding (but object contents stay mutable). Prefer const by default, let when reassigning, and avoid var.
Explain the event loop, call stack, microtasks, and macrotasks.
Tip: Synchronous code runs on the call stack. When it empties, the event loop drains all microtasks (Promise callbacks, queueMicrotask) before taking one macrotask (setTimeout, I/O). This is why a resolved Promise's .then runs before a setTimeout(0).
How does prototypal inheritance work in JavaScript?
Tip: Objects link to a prototype via [[Prototype]] (__proto__). Property lookups walk the prototype chain until found or null. class syntax is sugar over this — constructor functions plus prototype methods. Object.create(proto) creates an object with a chosen prototype.
What is the difference between == and === ?
Tip: === is strict equality (no type coercion); == performs type coercion before comparing, leading to surprises like 0 == "" or null == undefined being true. Always use === except the deliberate x == null check for null-or-undefined.
Explain this binding and how call, apply, bind, and arrow functions affect it.
Tip: this is determined by call site: method call → the object; plain call → undefined (strict) or global; new → the new instance. call/apply invoke with an explicit this (apply takes an args array); bind returns a new function with fixed this. Arrow functions have no own this — they capture the enclosing scope's.
What are Promises and how does async/await relate to them?
Tip: A Promise represents a future value in pending/fulfilled/rejected states, chained with .then/.catch. async/await is syntactic sugar over Promises: await pauses the async function until the Promise settles, with try/catch for errors. Use Promise.all for concurrency, Promise.allSettled when failures are tolerable.
What is debouncing vs throttling?
Tip: Debounce delays execution until activity stops for N ms (good for search-as-you-type, resize). Throttle runs at most once per N ms regardless of how often it is called (good for scroll, mousemove). Both limit how often an expensive handler fires.
InterviewEra generates role-specific questions using your actual projects and skills. Get scored feedback on technical depth, clarity, and structure — free to start.