Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Accessing Object Methods

You invoke an object method using the following syntax:

objectName.methodName()

If you call the fullName property with (), it will execute like a function.

Example

name = person.fullName;

Adding a Method to an Object

Adding a new method to an object is straightforward.

Example

person.name = function () {
  return this.firstName + ” “ + this.lastName;
};

Using JavaScript Methods

In this example, JavaScript’s toUpperCase() method is used to convert text to uppercase.

Example

person.name = function () {
  return (this.firstName + ” “ + this.lastName).toUpperCase();
};