Most asked JavaScript interview questions with detailed answers. Covers closures, promises, event loop, prototypes, and ES6+ features.
JavaScript is a lightweight, interpreted programming language with first-class functions. It is most well-known as the scripting language for Web pages, but it's also used in non-browser environments such as Node.js.
var is function-scoped and hoisted. let is block-scoped and not hoisted. const is block-scoped, not hoisted, and cannot be reassigned. Use const by default, let when reassignment is needed, avoid var.
A closure is a function that has access to its outer function's scope even after the outer function has returned. Closures are created every time a function is created, at function creation time.
The event loop is what allows JavaScript to perform non-blocking operations. It continuously checks the call stack and callback queue, pushing callbacks to the stack when it's empty.
Hoisting is JavaScript's default behavior of moving declarations to the top of the current scope. Variable declarations (var) and function declarations are hoisted, but not initializations.
== performs type coercion before comparison (loose equality). === compares both value and type without coercion (strict equality). Always prefer === to avoid unexpected behavior.
A Promise is an object representing the eventual completion or failure of an asynchronous operation. It can be in one of three states: pending, fulfilled, or rejected.
async/await is syntactic sugar over Promises. An async function always returns a Promise. await pauses execution until the Promise resolves, making async code look synchronous.
Every JavaScript object has a prototype property. Prototype is an object from which other objects inherit properties. It's the mechanism by which JavaScript objects inherit features from one another.
undefined means a variable has been declared but not assigned a value. null is an intentional absence of value — it must be explicitly assigned.
Arrow functions are a shorter syntax for writing functions introduced in ES6. They do not have their own this, arguments, super, or new.target. They cannot be used as constructors.
Destructuring is a JavaScript expression that allows unpacking values from arrays or properties from objects into distinct variables. Example: const { name, age } = person;
The spread operator (...) allows an iterable to be expanded in places where zero or more arguments or elements are expected. Example: const newArr = [...arr1, ...arr2];
A higher-order function is a function that takes one or more functions as arguments, or returns a function as its result. Examples: map, filter, reduce.
All three change the this context. call() invokes immediately with comma-separated args. apply() invokes immediately with an array of args. bind() returns a new function with bound this.
Event delegation is a technique of attaching a single event listener to a parent element instead of multiple listeners on child elements. It uses event bubbling to handle events efficiently.
Debouncing ensures a function is only called after a specified time has elapsed since its last invocation. Useful for search inputs, resize events to prevent excessive function calls.
Throttling limits function execution to once per specified time period. Unlike debouncing, it guarantees execution at regular intervals. Useful for scroll and mousemove events.
map() returns a new array with the results of calling a function on every element. forEach() executes a function for each element but returns undefined. Use map when you need a new array.
Generator functions can be paused and resumed. They use the function* syntax and yield keyword. They return a Generator object which is an iterator.
Sign up free to access complete notes — DSA, System Design, HR and more.
🚀 Access Full Notes Free →Build a professional resume to complement your preparation.
Build Free Resume →