3

When I execute the following code in JavaScript:

        const youtuber = {
            name: "rishi",
            content: "Politics",
            feature: function(){
                console.log(`My fav youtuber is ${this.name} and I like his view on ${this.content}.`)
            }
        }

        youtuber.feature();
        let youtubeFun = youtuber.feature;
        youtubeFun();

I get this output:

My fav youtuber is rishi and I like his view on Politics. My fav youtuber is and I like his view on undefined.

Can someone please explain why in second line of output there is no value in place of name and content?

Ahsok
  • 31
  • 4
  • 1
    The value of `this` is determined by how you call the function. You called it in such a way that `this` is the window object (in non-strict mode) or undefined (in strict mode) – Nicholas Tower Jul 08 '21 at 20:05

0 Answers0