Javascript methods guide - online javascript guide - javascript functions

Sponsored Links

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 refered. 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.

Assignments

  1. What do you think following methods do?
    1. Math.tan(3);
    2. Math.sqrt(4);
    3. document.write("www.webdevelopersnotes.com");
    4. window.close();
    5. window.scroll();
  2. Which method is used to open a new document window? (Take a guess!)

Click here for possible answers



Page contents: Javascript methods guide - online javascript guide - javascript functions

AddThis Social Bookmark Button

JavaScript Tutorial