Most computer programming languages provide a Math library which facilitates common or complicated mathematical operations. In object-oriented programming, it may take the form of an object with properties and methods to perform those functions. For instance, the JavaScript Math object provides constant values such as E (Euler’s number), LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2, and SQRT2. It includes methods which allow the programmer to make mathematical calculations like square roots, rounding, trigonometry functions, and more.

In JavaScript, the Math object can be used directly to access one of its properties or methods, as shown in the following JavaScript code below.

var x = 2 * Math.PI * 32;var y = Math.sqrt(4);

The example shows the use of the PI property and a call to the sqrt() method.

Programming terms