1

I have a simple javascript where I define an object and a function as its property. When I try to call the function from the object, it throws is not a function error

Here's my code block

var name = {
    firstName: 'Rahul',
    lastName: 'Sharma',
    fullName: function() {

        return this.firstName + ' ' + this.lastName;
    }
};

document.write('Full name is ' + name.fullName());

Throws error -

Uncaught TypeError: name.fullName is not a function

What am I doing wrong here?

0 Answers0