Keyed records
Represent named application data such as configuration, records, or grouped state.
JavaScript · Class
Object is JavaScript’s general-purpose object type for keyed collections and complex entities. Objects are commonly created with literals and usually inherit from Object.prototype.
Object is JavaScript’s general-purpose object type. Use object literals for ordinary records, or call Object with a value when you specifically need its conversion behavior; objects normally inherit from Object.prototype unless their prototype is null or comes from another null-prototype object.
Object(value)| Name | Type | Description |
|---|---|---|
value | any | The optional value to convert into an object; null and undefined produce an empty object, existing objects are returned, and other values produce corresponding wrapper objects. |
An object representing the input; for null or undefined, an empty object; for an existing object, the same object.
const settings = Object.create(null);
settings.theme = "dark";
console.log(settings.theme);
console.log(Object.getPrototypeOf(settings));Creates a dictionary-like object without inherited prototype properties, then reads its own data.
Represent named application data such as configuration, records, or grouped state.
Use a prototype-free dictionary when inherited properties should not participate in lookup.
Model richer entities by combining properties, methods, and prototype-based behavior.
Object is the built-in type used for keyed collections and more complex entities. Most objects inherit properties and methods from Object.prototype, unless they have a null prototype or descend from one.
Follow-up: How can you create an object without that inheritance? Use Object.create(null), producing a null-prototype object.
An object can be created with the Object() constructor or with object-literal syntax. Object literals are generally the concise choice for initializing ordinary records.
Follow-up: What alternative lets you choose the prototype? Object.create() allows the prototype object to be selected directly.
Object() turns its input into an object. With null or undefined it creates an empty object; an existing object is returned unchanged; other values produce an object corresponding to that value’s type.
Follow-up: Why might Object(value) differ from a literal? It performs conversion and may create a wrapper object for a primitive, whereas a literal creates a plain object.
Object.create()Object.assign()Object.getOwnPropertyNames()Object.prototype