Interview Q&A / JavaScript

INTERVIEW Q&A · 71 QUESTIONS

JavaScript interview questions

Closures, the event loop, this, promises and the core language questions every frontend round asks.

  1. How do you check whether a property exists on an object?

    Use Object.hasOwn(obj, key) for own properties and the in operator to include inherited ones. Comparing to undefined is unreliable, because a property can exist and hold undefined.

    BeginnerQuick answer1 min read
  2. Is JavaScript pass by value or pass by reference?

    JavaScript is always pass by value. For objects, the value passed is a reference, so a function can change the object's contents but cannot make the caller's variable point to a different object.

    BeginnerQuick answer1 min read
  3. What do Object.keys, Object.values, Object.entries and Object.fromEntries do?

    keys gives an array of own enumerable property names, values gives their values, and entries gives [key, value] pairs. fromEntries does the reverse and builds an object from pairs, which makes transforming objects easy.

    BeginnerQuick answer1 min read
  4. What is the difference between a shallow copy and a deep copy of an object?

    A shallow copy duplicates only the top level, so nested objects are still shared with the original. A deep copy duplicates every level, so the two are fully independent. Spread and Object.assign are shallow; structuredClone is deep.

    BeginnerQuick answer1 min read