JavaScript Interview Questions - JS Interview Prep
50 Questions Available
Comprehensive collection of 50 essential JavaScript interview questions covering ES6+, closures, promises, async/await, and modern JavaScript concepts. Free JavaScript, JS interview questions with answers. JavaScript JS interview prep guide.
All Questions & Answers
What is JavaScript and what are its main features?
JavaScript is a high-level, interpreted programming language. Main features include dynamic typing, prototype-based OOP, first-class functions, closures, event-driven programming, asynchronous with promises/async-await, and runs in browsers and Node.js.
What is the difference between let, const, and var?
var is function-scoped, hoisted, can be redeclared. let is block-scoped, hoisted but not initialized (TDZ), cannot be redeclared. const is block-scoped, must be initialized, cannot be reassigned. Use const by default, let when reassignment needed, avoid var.
What is hoisting in JavaScript?
Hoisting moves variable and function declarations to top of scope before execution. var declarations are hoisted and initialized with undefined. let/const are hoisted but not initialized (Temporal Dead Zone). Function declarations are fully hoisted.
What is closure in JavaScript?
Closure is function that has access to outer function's variables even after outer function returns. Inner function "closes over" outer scope. Used for data privacy, function factories, module patterns. Common in callbacks and event handlers.
What is the difference between == and ===?
== performs type coercion (converts types before comparison). === performs strict equality (no type coercion, compares type and value). Use === for predictable comparisons. == can lead to unexpected results.
What are arrow functions?
Arrow functions are concise function syntax introduced in ES6. Syntax: (params) => expression. No own this (inherits from outer scope), no arguments object, cannot be used as constructors, implicit return for single expression.
What is the difference between null and undefined?
undefined means variable declared but not assigned value. null is intentional absence of value (assigned). typeof undefined is "undefined", typeof null is "object" (bug). Use null for intentional empty values, undefined for uninitialized.
What is the event loop?
Event loop handles asynchronous operations. JavaScript is single-threaded. Call stack executes synchronous code. Callback queue holds async callbacks. Event loop moves callbacks from queue to stack when stack is empty. Enables non-blocking I/O.
What are promises?
Promise represents eventual completion of async operation. States: pending, fulfilled, rejected. Methods: then() (success), catch() (error), finally() (cleanup). Can chain promises. Better than callbacks for error handling and readability.
What is async/await?
async/await is syntactic sugar over promises. async function returns promise. await pauses execution until promise resolves. Errors caught with try/catch. Makes asynchronous code look synchronous. More readable than promise chains.