JavaScript interview questions
JavaScript interview questions and answers
Prepare for JavaScript interviews with focused questions on types, equality, scope, closures, arrays, objects, prototypes, classes, modules, promises, async/await, the event loop, DOM, fetch, and regex.
JavaScript technical interview topics
Beginner
JavaScript data types
What are the primitive data types in JavaScript?
JavaScript primitive values include string, number, bigint, boolean, undefined, symbol, and null. Objects are reference values and include arrays, functions, dates, maps, sets, and most structured data.
- JavaScript data types
- primitive types
- typeof interview question
Beginner
Equality and comparison
What is the difference between == and === in JavaScript?
Strict equality with === compares values without type conversion. Loose equality with == may convert types first, which can hide bugs, so modern JavaScript code usually prefers ===.
- JavaScript equality
- double equals triple equals
- comparison interview question
Intermediate
Scope and closures
What is a closure in JavaScript?
A closure is a function that keeps access to variables from the lexical environment where it was created, even after the outer function has finished running.
- JavaScript closure
- closure interview question
- lexical environment
Beginner
Arrays
When would you use map, filter, and reduce?
Use map to transform each item, filter to keep only matching items, and reduce to combine a list into one accumulated result such as a total, lookup object, or grouped collection.
- JavaScript array methods
- map filter reduce
- array interview question
Intermediate
Objects
How do object references work in JavaScript?
Objects are assigned and passed by reference value. Two variables can point to the same object, so mutating through one variable is visible through the other unless a copy is made.
- JavaScript objects
- object reference
- object interview question
Intermediate
Prototypes
What is the prototype chain?
When a property is not found directly on an object, JavaScript looks up that object's prototype, then the prototype's prototype, until it finds the property or reaches null.
- JavaScript prototype
- prototype chain
- prototypal inheritance
Intermediate
Classes
Are JavaScript classes different from prototypes?
Class syntax is a clearer way to define constructor-based objects and prototype methods. It does not replace prototypes; it builds on the same prototype model.
- JavaScript classes
- class syntax
- prototype class interview
Beginner
Modules
Why use JavaScript modules?
Modules make dependencies explicit with imports and exports, keep file-level scope isolated, and help organize reusable code without relying on globals.
- JavaScript modules
- import export
- ES module interview question
Intermediate
Promises
What problem do promises solve?
Promises represent asynchronous work that may fulfill or reject later. They make it possible to chain async steps and centralize error handling without deeply nested callbacks.
- JavaScript promises
- promise interview question
- asynchronous JavaScript
Intermediate
Async/await
How is async/await related to promises?
An async function always returns a promise, and await pauses that function until a promise settles. It is syntax for writing promise-based logic in a more sequential style.
- async await interview question
- JavaScript async
- await promise
Intermediate
Event loop
What is the event loop in JavaScript?
The event loop coordinates script execution, rendering, tasks, and microtasks. It lets JavaScript handle asynchronous callbacks while still running on a single main thread in the browser.
- JavaScript event loop
- microtasks macrotasks
- event loop interview question
Intermediate
DOM events
What is event delegation?
Event delegation attaches one listener to a shared ancestor and handles events from child elements through bubbling. It reduces listeners and works well for dynamic lists.
- event delegation
- DOM events
- JavaScript event interview question
Intermediate
Fetch and APIs
What should you check after calling fetch?
A fetch promise resolves for many HTTP error responses, so code should check response.ok or status, parse the expected body format, and handle network or parsing failures.
- JavaScript fetch
- Fetch API interview question
- HTTP response
Intermediate
Regular expressions
When should you use a regular expression in JavaScript?
Use a regular expression when text matching, validation, extraction, or replacement follows a pattern. For complex parsing, a dedicated parser can be clearer and safer.
- JavaScript regex
- regular expression interview question
- RegExp