Online JavaScript Guide – Methods

Online JavaScript Guide – Methods cover image
  1. Home
  2. JavaScript
  3. Online JavaScript Guide – Methods

Methods define functions performed by an object. Making a reference to an object method is similar to referencing its property. Thus, document.write(); calls the write() method of the document object.
Herein lies an important difference in how methods and properties are referred. Methods are always followed by a pair of parenthesis.

Some methods take a value part inside the parenthesis. You would know this by now since you have encountered the write() method in the previous sessions. To refresh your memory here is the code again:

document.write("I Love JavaScript");

The text I Love JavaScript is passed as a value to the write() method of the document object. The main function of this method is to take the value and display it in the browser window.

Different objects have different methods associated with them. The submit() method of a form object causes the form to be submitted. The log() method of the Math object computes the logarithm of the number supplied.

document.myform.submit();

causes myform to be submitted.

Math.log(2);

computes the logarithm of 2. The number is passed to the method inside the parenthesis and is called the argument.
Similarly, in the example before, I Love JavaScript was the argument passed to the write() method.

JavaScript