# JavaScript - Prototypal Inheritance with  Object.create

In this article, we will cover how Object.create can be used for prototypal inheritance.

let's create an object using Object.create

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682513029002/4695681b-3f23-44df-94d3-6170fd45263f.png align="center")

In the above code snippet, we created a user object with one property and a function. Then we are passing that user object to Object.create and store the result in user1.

Can you guess what will be the output for the conole.log(user1) statement?

if you open the console you will see an empty object

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682513312053/f19e0373-af63-42d4-899b-7da6d82d12c7.png align="center")

But, if you expand that object, you will see a special property \[\[Prototye\]\] which has the user object properties and a bunch of other methods.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682513424091/1ec839c2-c40a-41e9-93a9-d0959d7dc3e1.png align="center")

The user object that we pass to Object.create is set on the Prototype of user1 object.

Now, let's access the state property on user1

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682513666270/c1c97ff6-68f4-43e4-b3e3-6575427c4c20.png align="center")

Here, user1.state will print "Delhi". First, state property is checked on user1, it is not found there. Then, it is checked on its prototype, it is found there, so it uses that.

let's verify that the state is not user1's property

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682514086827/399e3403-b907-4254-a8f7-ba0412d811ea.png align="center")

In the above snippet, you can see **user1.hasOwnProperty('state')** returns false.

Now you must be wondering from where **hasOwnProperty** methods came. In javascript all objects eventually point to Object.Prototype

In our case chain is as follows

user1 Prototype =&gt; user Prototype =&gt; Object Prototype

**hasOwnProperty** is available on Object Prototype.

when we ran **user1.hasOwnProperty('state'),** it tried to find **hasOwnProperty** on user1, it is not found there. Then, it tried to find it on user Prototype, It is not found there as well. Then, it tried to find it on Object Prototype. It is found there.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682515139279/6de33566-028d-46a2-aa97-b12556b3931f.png align="center")

you can see that the last two statements in the above code snippet return true

Now let's define state property on user1 and run console.log(user1.state)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682515551069/574abcfa-ce8f-4490-aa7a-62afdb03e94d.png align="center")

In this case, state property is found on user1 itself, so it will not look any further.

Also when we run user1.printName(). The printName method is taken from the user1 prototype, as it is not defined on user1. But the state property is found on user1, so, it will be taken from there and not from its prototype.

If a property is not found on the object and also not found anywhere on the prototype chain, then undefined is returned.
