.

Math object in JavaScript Assignment Help

Math object in JavaScript

Math object used to accomplish mathematical calculations in an efficient manner.

22.1 Math object properties


Math object in JavaScript Assignment Help Through Online Tutoring and Guided Sessions at MyAssignmentHelp


Math has the following properties such as Math.E, Math.PI, Math.SQRT2, Math.SQRT1_2, Math.LN2, Math.LN10, Math.LOG2E, Math.LOG10E. The program illustrates the purpose of those properties of Math object.

Example:

Javascript math object img1

Ouput:

Javascript math object img2

22.2 Math Methods

Method

Purpose

Example

abs(x)

Returns only the value of x. Not sign either + or -.

var res=Math.abs(-1);

output :

1

acos(x)

Returns the trigonometry arccos value of x in

radians

var res=Math.acos(-1);

output:

3.14

asin(x)

Returns the trigonometry arcsin value of x in radians

var res= Math.asin(-1);

output:

-1.57

atan(x)

Returns the trigonometry arctan value of x in radians

var res= Math.atan(-1);

output:

-0.78

atan2(y, x)

Returns the arctangent value.  The value lies in between +pi and -pi

var res=Math.atan2(0, -0);

output:

3.14

ceil(x)

It rounds the value and return the whole integer.

var res=Math.ceil(98.94);

output:

99

cos(x)

Cosine of given input as output

var res=Math.cos(90);

output:

-0.44

exp(x)

Euler's constant to the power of given input as output

var res=Math.exp(1);

Output:

2.71

floor(x)

It truncates the decimal part  

var res=Math.floor(20.56);

Output:

20

log(x)

It displays natural logarithmic value of given input

var res=Math.log(10);

output:

2.30

max(x, y, z, ..., n)

It displays the maximum value from the given inputs

var res=max(6,8,10);

output:

10

min(x, y, z, ..., n)

It displays the minimum value from the given inputs

var res=min(6,8,10);

output:

6

.