The Object constructor creates an object wrapper for the given value.
- If the value is
nullorundefined, 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().
Syntax
new Object() new Object(value)
Parameters
value- Any value.
Examples
Creating a new Object
let o = new Object()
o.foo = 42
console.log(o)
// Object { foo: 42 }
Using Object given undefined and null types
The following examples store an empty Object object in o:
let o = new Object()
let o = new Object(undefined)
let o = new Object(null)
Specifications
| Specification |
|---|
| ECMAScript (ECMA-262) The definition of 'Object constructor' in that specification. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Object() constructor | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support 3 | Safari Full support 1 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
Legend
- Full support
- Full support
