How to define methods for an Object in JavaScript?


Methods are the functions that let the object do something or let something is done to it. There is a small difference between a function and a method – at a function is a standalone unit of statements and a method is attached to an object and can be referenced by this keyword.

Methods are used for everything from displaying the contents of the object to the screen to performing complex mathematical operations on a group of local properties and parameters. 

Here’s an example showing how to use the write() method of the document object to write any content on the document.

document.write("This is test");

Updated on: 03-Oct-2019

69 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements