# Basics

Instance methods are functions that are defined on the prototype of an object's class. They can be called on instances (objects) of that class, and have access to the properties of the instance through `this` keyword.

Here is an example of a class with an instance method:

```javascript
class Person {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }

  sayHello() {
    console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);
  }
}

const person1 = new Person('John', 30);
person1.sayHello(); // "Hello, my name is John and I am 30 years old."
```

In this example, the `Person` class has a `sayHello` method that logs a greeting to the console. The method is defined on the class's prototype, so it can be called on any instance of the `Person` class.

Instance methods are useful for defining behaviour that is specific to an object and that requires access to the object's properties. They can also be overridden by subclasses to customize the behavior for specific types of objects.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://demirels-organization.gitbook.io/javascript-tutorial/instance-method/basics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
