Skip to main content
FREE Mock interview & resume review with Sumit. Free right now, no payment needed.Book a slot

Object.create()

Topic 5JavaScript Part 4 (OOP)

Object.create()

Introduction

The `Object.create()` method creates a new object with the specified prototype and properties.

Key Concepts and Definitions

Object.create()

Creates a new object with the specified prototype and properties.

Examples

Object.create() Example:

const proto = {
  greet() {
    console.log(`Hello, my name is ${this.name}`);
  }
};

const person = Object.create(proto);
person.name = 'Alice';

person.greet(); // Hello, my name is Alice

Using Object.create() for Prototype Chain:

const proto = { greet: function () { console.log('Hello!'); } };
const obj = Object.create(proto);

obj.greet(); // Hello!

Interview guide discussion

(0)

Join the discussion — login to comment and help other developers.

Login to comment
Object.create() | JioCoder