|
||||||||||||||||||||||||||||||||||||||||
|
Skill Level: Beginner / Intermediate Skills Required: Objects and Basic JavaScript
Mathematical functions like addition, subtraction, averages, etc. are inevitable if you are working on a page that has to compute something. JavaScript solves the problem by giving you a complete Math Object to carry out various functions easily. This article discusses the various properties and methods available to us.
The predefined Math object has properties and methods for mathematical constants and functions. You don't create a new Math object. Its already created for you, just as window and document objects. For example, the Math object's PI property has the value of pi (3.1415...), which you would use in an application as Math.PI. A simple function that can compute the area of a circle is given below: function area (radius)
Similarly, standard mathematical functions are methods of Math. These include trigonometric, logarithmic, exponential, and other functions. For example, if you want to use the trigonometric function sine, you would write Math.sin(1.56).
Number Object: Alongwith the Math Object you will find the Number object quite useful for advanced tasks. The different properties of this object and their description is provided below:
| ||||||||||||||||||||||||||||||||||||||||