JavaScript Math Object - Javascript Objects

What is JavaScript Math Object?

The Math object in JavaScript is a built in object which allows you to perform mathematical operations.

Math object in JavaScript has properties and methods that has mathematical constraints and functions. Like all other objects, Math is not a constructor.

All the methods and properties of Math object are static and they can be called by using Math as an object without creating it.

So, you refer to the constant pi as Math.PI and you call the sine function as Math.sin(x), where x is the method's argument.
Syntax:
Below is the syntax to call the properties and methods of Math -

What are Math Properties?

Below are the list of all the properties of Math and their description.

Property
Description
E
Euler's constant and the base of natural logarithms, approximately 2.718.
LN2
Natural logarithm of 2, approximately 0.693.
LN10
Natural logarithm of 10, approximately 2.302.
LOG2E
Base 2 logarithm of E, approximately 1.442.
LOG1E
Base 10 logarithm of E, approximately 0.434.
PI
Ratio of the circumference of a circle to its diameter, approximately 3.14159.
SQRT1_2
Square root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707.
SQRT2
Square root of 2, approximately 1.414.

In the upcoming sections, we will have a few examples which illustrates the use of Math properties.

What are JavaScript Math Methods?

Below are the list of the methods associated with Math object and their description.

Method

Description

abs()

Returns the absolute value of a number.

acos()

Returns the arccosine (in radians) of a number.

asin()

Returns the arcsine (in radians) of a number.

atan()

Returns the arctangent (in radians) of a number.

atan2()

Returns the arctangent of the quotient of its arguments.

ceil()

Returns the smallest integer greater than or equal to a number.

cos()

Returns the cosine of a number.

exp()

Returns EN, where N is the argument, and E is Euler's constant, the base of the natural logarithm.

floor()

Returns the largest integer less than or equal to a number.

log()

Returns the natural logarithm (base E) of a number.

max()

Returns the largest of zero or more numbers.

min()

Returns the smallest of zero or more numbers.

pow()

Returns base to the exponent power, that is, base exponent.

random()

Returns a pseudo-random number between 0 and 1.

round()

Returns the value of a number rounded to the nearest integer.

sin()

Returns the sine of a number.

sqrt()

Returns the square root of a number.

tan()

Returns the tangent of a number.

toSource()

Returns the string "Math".

In the upcoming sections, we will have a few examples which illustrates the use of the methods associated with Math.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Javascript Objects Topics