theory.js

Objects & the Prototype Chain

Object Creation

JavaScript allows creating objects in multiple ways.

  • Object Literals: The simplest way to create objects using `{ key: value }`.
  • new Object(): Creates an object using the Object constructor.
  • Object.create(): Creates an object with a specified prototype.
// Object literal
let person = { name: "Jake", age: 25 };

// new Object()
let user = new Object();
user.name = "Alice";

// Object.create() with no prototype
let obj = Object.create(null);