HomebaseWorks

JavaScript interview questions

Frequently asked JavaScript questions, answered the way an experienced developer would explain them in a technical round.

EWritten by the HomebaseWorks editorial team · reviewed 26 Oct 2026
1
What is the difference between == and ===?

=== compares value and type with no conversion, so 0 === "0" is false. == converts types before comparing, so 0 == "0" is true, and the conversion rules have surprising cases such as null == undefined being true. I use === by default and only use == null when I deliberately want to catch both null and undefined.

2
Explain closures with an example.

A closure is a function that keeps access to variables from the scope where it was defined, even after the outer function has returned. For example, a makeCounter function can hold a private count variable and return a function that increments it, and nothing outside can change count directly. I have used closures for debounce helpers and for keeping private state inside a module.

3
How does this work in JavaScript?

For a regular function, this depends on how it is called: as obj.method() it is obj, as a plain call it is undefined in strict mode, and with new it is the newly created object. call, apply and bind let you set it explicitly. Arrow functions have no this of their own and use the this of the surrounding scope, which is why they are convenient inside callbacks.

Advertisement
4
Explain the event loop.

JavaScript runs on one thread with a call stack. When the stack is empty, the engine first runs every queued microtask, such as promise callbacks, and then takes the next task, such as a timer or an event handler. That is why a resolved promise's then callback runs before a setTimeout with a zero delay.

5
What is the difference between map, filter and reduce?

map returns a new array of the same length with each element transformed. filter returns a new array containing only the elements that pass a test. reduce combines all elements into a single value; for example, cart.reduce((sum, item) => sum + item.price, 0) gives the cart total.

6
How do you handle errors with async/await?

I wrap awaited calls in try/catch, or attach a catch to the promise that the async function returns. With fetch I also check res.ok, because fetch only rejects on network failure, not on HTTP errors such as 404 or 500. For several independent requests I use Promise.all inside the try, or Promise.allSettled when partial results are acceptable.

Practise out loud. Say each answer once as written, then again in your own words with your own number or story.

Have a number ready. "My JavaScript score is at benchmark on a timed test" is a stronger answer than "I am good at it". Take the test and quote the result.

Advertisement
Continue with JavaScript4 lessons · 1 interview set · 1 test · 1 certificate
Not tested

More in Programming