The Math object’s methods allow you to perform many common mathematical calculations. As shown previously, an object’s methods are called by writing the name of the ob-ject followed by a dot (.) and the name of the method. In parentheses following the method name is the argument (or a comma-separated list of arguments) to the method. For example, to calculate and display the square root of 900.0 you might write
document.writeln( Math.sqrt( 900.0 ) );
which calls method Math.sqrt to calculate the square root of the number contained in the parentheses (900.0), then outputs the result. The number 900.0 is the argument of the Math.sqrt method. The preceding statement would display 30.0. Some Math object methods are summarized in Fig. 11.1.
The Math object defines several commonly used mathematical constants, summarized in Fig. 11.2. [Note: By convention, the names of constants are written in all uppercase let-ters so they stand out in a program.]
Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.