Advertisement
728x90
The Object.create() method is used to create a new object with the specified prototype object and properties. i.e, It uses an existing object as the prototype of the newly created object. It returns a new object with the specified prototype object and properties.
javascript
1const user = {
2 name: "John",
3 printInfo: function () {
4 console.log(`My name is ${this.name}.`);
5 },
6 };
7
8const admin = Object.create(user);
9
10admin.name = "Nick"; // Remember that "name" is a property set on "admin" but not on "user" object
11
12admin.printInfo(); // My name is NickAdvertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 33
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
203of476