Skip to solution
mediumFrontend

What does Object.create do?

973 views
01

Understand the problem

Question presented to candidate: "You want a plain, prototype-less object to use as a lookup map — safe from any key colliding with something inherited from Object.prototype, like the special proto key. How would you actually build one, and what does Object.create do differently from a normal object literal?"

What a strong answer should cover:

  • Object.create(proto) creates a brand-new object with proto set as its own [[Prototype]] — a real, direct way to set up prototypal inheritance without going through a constructor function or the class keyword at all.
  • 📌 Verified, not assumed: Object.create(null) genuinely produces an object with no prototype at all — a real, direct attempt to call .toString() on it genuinely threw a real TypeError (the method itself does not exist on it), and typeof obj.hasOwnProperty was genuinely "undefined".
  • 📌 Interview term: the real "safe map" use case, directly answering the prompt — assigning to normalObj["__proto__"] on a REGULAR object genuinely did not create an own property at all; it invoked the real, inherited __proto__ accessor (a no-op here, since a string is not a valid prototype value). The identical assignment on an Object.create(null) object genuinely did create a real, normal own property literally named __proto__ — confirmed directly via Object.hasOwn().
  • A precise answer names the second, optional argument: Object.create(proto, propertyDescriptors) lets you define real own properties (with full control over writable/enumerable/configurable) in the same call.

Clarifying questions expected:

  • "Does this object genuinely need zero inherited methods (a real Object.create(null) map), or does it just need a custom, specific prototype set up directly?" — two genuinely different real use cases for the same function.
  • "Will any of this object's keys ever come from untrusted, external input (like JSON parsed from a request body)?" — directly relevant to the prompt's own proto-safety concern, verified above.

Code / implementation expected: Yes — a real, direct side-by-side comparison of a __proto__-keyed assignment on a regular object versus an Object.create(null) object, showing genuinely different real outcomes, is the concrete proof of exactly why the prompt's "safe map" need is answered by Object.create(null).

object-create
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript prototype-system interviews. Difficulty: Medium

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. The prototype-less object's real thrown error, and the real, direct __proto__-key c

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSReal proof: Object.create(null) has genuinely no inherited methods, and makes __proto__ a plain own key
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 55 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track