The usual way is an object literal, such as { name: "John" }. You can also call new Object(), use Object.create() to choose the new object's prototype, or call a constructor function with new.
An object literal is the shortest form and covers most cases.
new Object() does the same thing with more code, so it is rarely used.
Object.create(proto) makes an object whose prototype is proto, and Object.create(null) makes one with no prototype at all, which suits a plain dictionary.
A constructor function called with new builds many objects of the same shape, which is what the class syntax does today.
Saved in this browser - sign in to keep your review list.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Keep going - a few more words and AI can grade it.
Interview lens
How interviewers actually use this question
Likely follow-ups
What does Object.create(null) give you that an empty literal {} doesn't, and when would you use it?It inherits no keys like toString or constructor, so any string is a safe key. Also name the cost: the object has no built-in methods.
How does the class syntax relate to constructor functions?Classes use the same prototype mechanism with cleaner syntax. A strong answer adds a real difference, such as a class throwing when called without new.
Most of the time I create objects with an object literal, curly braces with the properties inside, because it's the shortest form and covers most cases.
You can also write new Object() and add properties after, but it does the same thing with more code, so I rarely see it.
Object.create lets me pick the new object's prototype, and Object.create(null) makes an object with no prototype at all, which works well as a plain dictionary.
When I need many objects of the same shape, I call a constructor function with new, and today the class syntax does that same job.
The literal is my default. I only use Object.create(null) when I need a clean dictionary, because that object has no toString or hasOwnProperty to call.
Weak answers to avoid
Lists four syntaxes, no when-to-useA memorized list shows recall, not judgment. Say the literal is the default, then say when you would use Object.create or a constructor instead.
Treats Object.create(null) as the same as {}An empty literal inherits from Object.prototype, so keys like toString already exist on it. Object.create(null) has no prototype, which is why it suits a dictionary.
Talks about class as a separate object modelClass syntax builds objects the same way a constructor called with new does, through a prototype. Saying so shows you know what runs underneath.
Forgets that a constructor needs newCalling Person without new builds nothing. In sloppy mode this is the global object, in strict mode it throws. A class throws if you call it without new.
Interview lens
Likely follow-ups, what you can say, and the weak answers to avoid.