How to use Object.create in Javascript
The Object.create() method uses an existing object as a prototype to create a new object.
Prototype
The Object.create() method has the following prototypes:
Prototype #1
Object.create(proto)
Prototype #2
Object.create(proto, propertiesObject)
Parameters and return value
The Object.create() function takes proto as input in both prototypes, as well as an optional input, propertiesObject, in the second prototype.
proto: The prototype of the newly created object.protomust be an object or null.propertiesObject: The properties of the newly created object.
The Object.create() function returns a newly created object with the given prototype and properties.
Example
The following example demonstrates how to create an object using the Object.create() function in Javascript.
- The program creates an object
fruitwith the propertiesisFruitandprintFuit. - The program then creates another object,
newFruit, usingfruitas the prototype. It adds a new property,name, tonewFruitand overwrites its existing propertyisFruit. - The program calls the
printFruit()function, which displays information about the fruit using its properties.
// create objectconst fruit = {isFruit: false,printFruit: function() {console.log(`Is ${this.name} a fruit? ${this.isFruit}`);}};// create a new objectconst newFruit = Object.create(fruit);// create a new propertynewFruit.name = 'Mango';// overwrite the isFruit propertynewFruit.isFruit = true;newFruit.printFruit();
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved