Object

The Object constructor creates an object wrapper.

Syntax

// Object initialiser or literal
{ [ nameValuePair1[, nameValuePair2[, ...nameValuePairN] ] ] }

// Called as a constructor
new Object([value])

Parameters

nameValuePair1, nameValuePair2, ... nameValuePairN
Pairs of names (strings) and values (any value) where the name is separated from the value by a colon.
value
Any value.

Description

The Object constructor creates an object wrapper for the given value. If the value is null (en-US) or undefined (en-US), it will create and return an empty object, otherwise, it will return an object of a Type that corresponds to the given value. If the value is an object already, it will return the value.

When called in a non-constructor context, Object behaves identically to new Object().

See also the object initializer / literal syntax.

Properties of the Object constructor

Object.length
Has a value of 1.
Object.prototype (en-US)
Allows the addition of properties to all objects of type Object.

Methods of the Object constructor

Object.assign() This is an experimental API that should not be used in production code.
Creates a new object by copying the values of all enumerable own properties from one or more source objects to a target object.
Object.create() (en-US)
Creates a new object with the specified prototype object and properties.
Object.defineProperty()
Adds the named property described by a given descriptor to an object.
Object.defineProperties() (en-US)
Adds the named properties described by the given descriptors to an object.
Object.freeze()
Freezes an object: other code can't delete or change any properties.
Object.getOwnPropertyDescriptor() (en-US)
Returns a property descriptor for a named property on an object.
Object.getOwnPropertyNames() (en-US)
Returns an array containing the names of all of the given object's own enumerable and non-enumerable properties.
Object.getOwnPropertySymbols() (en-US) This is an experimental API that should not be used in production code.
Returns an array of all symbol properties found directly upon a given object.
Object.getPrototypeOf()
Returns the prototype of the specified object.
Object.is() (en-US) This is an experimental API that should not be used in production code.
Compares if two values are distinguishable (ie. the same)
Object.isExtensible() (en-US)
Determines if extending of an object is allowed.
Object.isFrozen() (en-US)
Determines if an object was frozen.
Object.isSealed() (en-US)
Determines if an object is sealed.
Object.keys() (en-US)
Returns an array containing the names of all of the given object's own enumerable properties.
Object.observe() This is an experimental API that should not be used in production code.
Asynchronously observes changes to an object.
Object.preventExtensions() (en-US)
Prevents any extensions of an object.
Object.seal() (en-US)
Prevents other code from deleting properties of an object.
Object.setPrototypeOf() (en-US) This is an experimental API that should not be used in production code.
Sets the prototype (i.e., the internal [[Prototype]] property)

Object instances and Object prototype object

All objects in JavaScript are descended from Object; all objects inherit methods and properties from Object.prototype (en-US), although they may be overridden. For example, other constructors' prototypes override the constructor property and provide their own toString() methods. Changes to the Object prototype object are propagated to all objects unless the properties and methods subject to those changes are overridden further along the prototype chain.

Properties

{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype', 'Properties') }}

Methods

{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype', 'Methods') }}

Examples

Example: Using Object given undefined and null types

The following examples store an empty Object object in o:

var o = new Object();
var o = new Object(undefined);
var o = new Object(null);

Example: Using Object to create Boolean objects

The following examples store Boolean objects in o:

// equivalent to o = new Boolean(true);
var o = new Object(true);
// equivalent to o = new Boolean(false);
var o = new Object(Boolean());

Specifications

Specification Status Comment
ECMAScript 1st Edition. Standard Initial definition. Implemented in JavaScript 1.0.
ECMAScript 5.1 (ECMA-262)
The definition of 'Object' in that specification.
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Object' in that specification.
Standard  

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help! (en-US)
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

See also