Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Object — creating objects and working with properties

Object is a built-in JavaScript function for creating objects and converting values to objects. It also exposes static methods for working with properties and prototypes. Distinguish an object's own properties from inherited properties.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

Object(value)
new Object(value)
Object.create(proto)
Object.keys(obj)
Object.hasOwn(obj, key)

Object is a built-in function that can also be called with new. Objects hold properties whose keys are strings or symbols. An object literal is usually sufficient for creating an ordinary object, for example const user = { name: "Ada" };.

Object() and new Object() create an empty object. Direct calls with null or undefined also create a new empty object. Object(value) returns an existing object without copying it and wraps other primitive values in objects; for example, Object(3) is not a primitive number.

Object.prototype provides inherited methods to ordinary objects. Object.create(proto) creates an object with the specified prototype; Object.create(null) creates one without a prototype. Property reads can reach the prototype, but Object.hasOwn(obj, key) checks only own properties. It is a static method: call it on Object, not on obj.

Object.keys(obj) returns only own, enumerable string keys: it excludes symbols and inherited properties. In the example, role is inherited and name is own. Object.hasOwn belongs to ECMAScript 2022; check its availability in older environments. This is ECMAScript functionality, not a Web API; working in Node.js does not prove browser support.

Examples

const base = { role: "reader" };
const user = Object.create(base);
user.name = "Ada";

console.log(user.role);
console.log(Object.hasOwn(user, "role"));
console.log(Object.hasOwn(user, "name"));
console.log(Object.keys(user).join(","));
console.log(Object(user) === user);

Result

reader
false
true
name
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources