Try to search your question here, if you can't find : Ask Any Question Now ?

Can somebody explain why i got a return of "undefined" while using "this" keyword

HomeCategory: stackoverflowCan somebody explain why i got a return of "undefined" while using "this" keyword
Avatarrupesh asked 3 months ago

I just started JS and only had this question based on the example below.

function Animal(name) {
    let animal = Object.create(Animal.prototype)
    this.name = name

    return animal
}

Animal.prototype.eat = function() {
    console.log(this.name +" is eating.")
}
let blackie = Animal("Blackie");
    blackie.name;
    blackie.eat();
1 Answers
Best Answer
AvatarJyoti answered 3 months ago
Your Answer

15 + 11 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com