Interview Q&A / JavaScript
JavaScript interview questions
Closures, the event loop, this, promises and the core language questions every frontend round asks.
Prefer rapid revision? Practise JavaScript short interview answers →
- 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 - 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 - 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 - 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