W3cubDocs

/JavaScript

Object.object

The Object creates an object wrapper for the given value.

  • If the value is null or undefined, 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

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Object() constructor 1 12 1 3 3 1
Mobile
Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
Object() constructor 1 18 4 10.1 1 1.0
Server
Node.js
Object() constructor Yes

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/Object