1.

What are Set and WeakSet?

Answer»

To understand inheritance using constructor function, we will see an example containing a Mammal parent function and Human child function. Also, make the Human’s Prototype have a reference of Mammal’s Prototype using Object.create. Human’s Prototype will have all methods of Mammal’s Prototype.

 Now, let’s look into “Human” in the console. As you can see it contains “Mammal” sleep and walk function in it’s __proto__.

But we have a major problem because the statement Human.prototype = Object.create(Mammal.prototype) wipes out any Human’s Prototype function and also it’s constructor.

We didn’t declared any Human’s Prototype function, but the constructor was wiped. 

So, we solve it by below code. It is using Human.prototype.constructor = Human to set the constructor back in “Human”.

Also, we are declaring Human’s Prototype function after Human.prototype = Object.create(Mammal.prototype)

... ... Human.prototype = Object.create(Mammal.prototype); Human.prototype.constructor = Human; Human.prototype.fly = function() {   return 'Flying with Gliders'; }

Let’s now complete the code and create two instances of “Human” as hari and harry. Both can access functions walk, sleep and fly.


Interview Tips for Freshers

The INDUSTRY is looking for candidates who can start with their work immediately and not the ones who are looking for a training. As a newbie in the IT Industry for a CAREER as UI DEVELOPER, it’s good to learn the VARIOUS UI frameworks like Vue.JS, React.JS, and Angular.js which are Javascript frameworks. To be shortlisted you can also take up some courses on these front-end technologies.

These javascript interview questions for beginners will help you to crack your javascript interview. Be prepared with the best interview questions for javascript and you will be able to pass the Javascript interview easily. All the best!



Discussion

No Comment Found