In JavaScript, objects are one of the most fundamental and versatile data types. They are collections of key-value pairs, where the keys (also called properties) are strings or symbols, and the values can be of any data type, including other objects, functions, or arrays.
Prototypal Inheritance: Objects can inherit properties and methods from other objects using prototypes.
Dynamic Structure: Objects can have properties added or removed dynamically.
Flexibility: They can store mixed data types and methods (functions that belong to the object).
You need to store a user's name, email, and a list of their favorite colors. Show me how you'd create that object and then add a new favorite color later.
What happens if you try to read a property that doesn't exist on an object — say, user.age when age was never set? What if you then assign to it?
Write a function that takes an object and a key, and returns true only if that key exists directly on the object (not inherited). How would you check that?
A teammate passes an object method as a callback to setTimeout, but inside the callback this is undefined. Why does that happen, and how would you fix it without changing the call site?
You're debugging a performance issue where a hot loop creates thousands of similar objects. What properties of object creation could you optimize, and how would you measure the impact?
Explain the difference between shallow and deep cloning an object. Give a real example where a shallow copy caused a bug in your codebase.
We're building a high-frequency trading module where every microsecond counts. How would you design the order object to minimize GC pressure and maximize property access speed? Mention hidden classes or inline caches if relevant.
A legacy codebase uses deep prototype chains for domain models. You've been asked to refactor toward composition. Walk me through the risks of the current hierarchy and how you'd migrate incrementally without breaking downstream consumers.
When would you choose Object.defineProperty with configurable:false over a TypeScript readonly modifier? What runtime guarantees does each actually give you?
Three teams own services that share a 'User' object shape across RPC boundaries. One team wants to add a nullable field, another wants to rename a key, and a third needs a new nested object. How do you govern this evolution without versioning hell?
We're migrating a 10-year-old prototype-heavy codebase to modern classes. The prototype chain includes circular references and dynamic property additions. What's your migration strategy, and how do you verify behavioral parity?
An internal library exposes a configuration object that consumers mutate directly, causing subtle bugs across repos. Propose an API design that prevents mutation while staying ergonomic for feature teams. How do you roll it out?