-1

I have come across this code

var person = {
    name: "joseph",
    age: 33,
    favSong: function killingInTheTameOf(){
        this.lyrics = "Those who died are justified";
    }
};

document.write(person.lyrics); //doesn't work

my question is about the this.lyrics variable,
what is the meaning of this?
how do i access it?
what does this refer to exactly? person?
i have read about this but none of the cases i learnd about covers this

1 Answers1

0

You need to call favSong in order to create the property lyrics.

var person = {
    name: "joseph",
    age: 33,
    favSong: function killingInTheTameOf(){
        this.lyrics = "Those who died are justified";
    }
};

person.favSong();
document.write(person.lyrics); //worksss
void
  • 33,471
  • 8
  • 45
  • 91