---
title: Object Methods
description: "### Example `var person = { firstName: \"John\", lastName : \"Doe\", id : 5566, fullName : function() { return this.firstName + \" \" + this.lastName; } };` ## The **this** Keyword In a function definition, `this` refers to the “owner” of the function. In…"
url: "https://apprentice.mn/docs/object-methods/"
updated: "2021-05-18"
category: Javascript
---

# Object Methods

### Example

     `var person = {
  firstName: "John",
  lastName : "Doe",
  id       : 5566,
  fullName : function() {
    return this.firstName + " " + this.lastName;
  }
};`

## The **this** Keyword

In a function definition, `this` refers to the “owner” of the function.

In the example above, `this` is the **person object** that “owns” the **fullName** function.

In other words, **this.firstName** means the **firstName** property of **this object**.

Read more about the `this` keyword at [JS this Keyword](https://www.w3schools.com/js/js_this.asp).

---

## JavaScript Methods

JavaScript methods are actions that can be performed on objects.

A JavaScript **method** is a property containing a **function definition**.

| Property | Value |
| --- | --- |
| firstName | John |
| lastName | Doe |
| age | 50 |
| eyeColor | blue |
| fullName | function() {return this.firstName + ” ” + this.lastName;} |

Methods are functions stored as object properties.

---

## Accessing Object Methods

You access an object method with the following syntax:

  *objectName.methodName()*

You will typically describe fullName() as a method of the person object, and fullName as a property.

The fullName property will execute (as a function) when it is invoked with ().

This example accesses the fullName() **method** of a person object:

### Example

      `name = person.fullName();`

If you access the fullName **property**, without (), it will return the **function definition**:

### Example

      `name = person.fullName;`

## Using Built-In Methods

This example uses the `toUpperCase()` method of the String object, to convert a text to uppercase:

       `var message = "Hello world!";
var x = message.toUpperCase();`

The value of x, after execution of the code above will be:

  HELLO WORLD!

---

## Adding a Method to an Object

Adding a new method to an object is easy:

### Example

      `person.name = function () {
  return this.firstName + " " + this.lastName;
};`        [https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fobject-methods%2F&linkname=Object%20Methods](https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fobject-methods%2F&linkname=Object%20Methods)[https://www.addtoany.com/add_to/mastodon?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fobject-methods%2F&linkname=Object%20Methods](https://www.addtoany.com/add_to/mastodon?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fobject-methods%2F&linkname=Object%20Methods)[https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fobject-methods%2F&linkname=Object%20Methods](https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fobject-methods%2F&linkname=Object%20Methods)[https://www.addtoany.com/share](https://www.addtoany.com/share)
