JavaScript: Creating Object

By Xah Lee. Date: . Last updated: .

There are 3 ways to create a object in JavaScript.

  1. Literal expression: {…} → Most useful, when you want to use it as a set of key/value pairs for data.
  2. Object.create() → Most powerful and flexible way to create object, because you can specify parent object, properties, property attributes, in one place.
  3. Keyword new, in new function_name() → complex behavior. Most useful when you are writing a object-oriented library.

Note: Array, Date, Regex, Function, etc are also objects. But we are not considering how to create them on this page.

Create Object Using Object.create()

JavaScript: Object.create

Creating Object by Literal Expression

JavaScript: Object Literal Expression {…}

Create Object Using Keyword “new”

Another way is using the keyword new followed by a function call. It is the most complex. For detail, see: JavaScript: What Does the Keyword “new” Do?

Parent of New Objects

JavaScript: Prototype and Inheritance

Object and Inheritance Topic

  1. JavaScript: Object System Overview
  2. JavaScript: What's Object?
  3. JavaScript: Prototype and Inheritance
  4. JavaScript: Creating Object
  5. JavaScript: Object Literal Expression {…}
  6. JavaScript: Find Object's Prototype
  7. JavaScript: How to Create Object with Parent X?
  8. JavaScript: Prevent Adding Property
  9. JavaScript: Determine Type of Object
  10. JavaScript: Primitive Value Object Wrapper
  11. JavaScript: Clone, Deep Copy Object/Array
  12. JavaScript: Test Equality of Objects

  1. JavaScript: Object Object
  2. JavaScript: Object.prototype
Like what you read? Buy JavaScript in Depth
or, buy a new keyboard, see Keyboard Reviews.