JavaScript Math - JAVASCRIPT: A Beginner’s Guide to Learning the Basics of JavaScript Programming (2015)

JAVASCRIPT: A Beginner’s Guide to Learning the Basics of JavaScript Programming (2015)

Chapter 18. JavaScript Math

Math is a built-in object in JavaSript, which has methods and properties for math functions and constants, but not a function object. Math is not considered a constructor in JavaScript, unlike other global objects. The methods and properties of JS Math are static. We can consider the constant pi as Math.PI; we can refer to the sine as Math.sin(x). Take note that the X refers to the argument of the method. In JavaScript, constants are prescribed with complete precision, thanks to real numbers (as opposed to integers).

Properties of Math in JS

Refer to the table below for the different math properties used in JavaScript




The Euler’s Constant, which is the base of natural logs, about 2.718


The natural log of 10, about 2.303


The natural log of 2, about 0.693


Base 10 log of E, about 0.434


Base 2 log of E, about 1.443


Sq. root of 2, about 1.414


Sq.root of ½ eq, 1 / sq. 2, about 0.707


Ratio of circle circum to the diam about 3.1415


Take note that the trigo functions (atan2(), atan(), acos(), asin(), tan(), cos(), sin()) return radians angles. In order to conv radians into degrees, you can divide using Math.PI and multiply it for reverse conversion.

In addition, the precision of math functions in JS are dependent on implementation. Hence, various browsers will yield varying results. Even similar engines on a different architecture or operating system may yield varying results.

Refer to the table below for the different Math Methods in JS

Methods Math.



Yields the absolute number value


Yields the number’s hyperbolic arcosine.


Yields the number’s arcosine


Yields the number’s hyperbolic arcsine


Yields the number’s arcsine


Yields the number’s hyperbolic arctangent


Yields the number’s arctangent

.atan2(x, y)

Yields the quotient’s arctangent arguments


Yields the number’s cube root


Yields the number prime zeros of a 32-bit int


Yields the min integer >= to x


Yields the number’s cosine


Yields the number’s hyperbolic cosine


Yields Ex (x=argument, E=Euler’s constant (log base)


Yields the biggest int <= to x


Yields the number’s nearest single precision float rep


Yields the sq root of the sum of sq of args


Yields the result of multiplying 32-bit int


Yields the number’s natural log


Yields the number’s base 2 log


Yields the number’s natural log of 1+x


Yields the number’s base 10 log


Yields the biggest zero or more numbers


Yields the min zero or more numbers

.pow(x. y)

Yields base to exp power


Yields a pseudo-random number between zero and 1


Yields the sign of the number, which indicates if x is zero, negative, or positive


Yields the number’s value rounded to the nearest int


Yields the number’s sine


Yields the number’s hyperbolic sine


Yields the number’s positive sq root


Yields the number’s tangent


Yields the number’s hyperbolic tangent


Yields the number’s integral part, which removes any fractional digits