Computer Science, asked by santoshgautamk1740, 1 year ago

How to define a method in JavaScript?

Answers

Answered by socalledharsh
0

JavaScript Methods

•JavaScript methods are actions that can be performed on objects.

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

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 full Name 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();

Adding a Method to an Object

Adding a new method to an object is ✓easy:

•Example

person.name = function () {

return this.firstName + " " + this.lastName;

};

------------------>thnx

Attachments:

socalledharsh: pls mark this as brainlist
Similar questions