MATH OBJECT IN JAVASCRIPT

 

Math Object :

 

The built-in Math object includes mathematical constants and functions. You do

not need to create the Math object before using it. Following table contains list of math

object methods: e.g. var x=56.899; alert(Math.ceil(x));

 

Sr.No

Method

Description

1

abs(x)

Returns the absolute value of a number.

This method helps return the absolute values of a number. Absolute value or modules essentially means a non-negative value of x.

For example:

var a = Math.abs(7.25); 

var b = Math.abs(-7.25);

var c = Math.abs(null);

var d = Math.abs("Hello");

var e = Math.abs(2-3);

OUTPUT :

7.25

7.25

0

NaN

1

2

cbrt(x)

Returns the cube root of a number.

Return Value: It returns the cube root of the given number.

For example:

document.write("Output : " + Math.cbrt(8));  

OUTPUT:2

3

ceil(x)

Returns the next integer greater than or equal to a given number(rounding up).

For example:

For example:

document.write("Output : " + Math.ceil(0.8));  

OUTPUT:1

4

floor(x)

Returns the next integer less than or equal to a given number (rounding down).

For example:

console.log("Result : " + Math.floor(.89));

OUTPUT :

0

var a = Math.floor(0.60);  OUTPUT :-   0

var b = Math.floor(0.40); OUTPUT :-   0

var c = Math.floor(5); OUTPUT :-   5

var d = Math.floor(5.1); OUTPUT :-   5

var e = Math.floor(-5.1); OUTPUT :-   -6

var f = Math.floor(-5.9); OUTPUT :-   -6

5

max(x, y, ...)

Returns the highest-valued number in a list of numbers.

For example:

var b = Math.max(0, 150, 30, 20, 38);

OUTPUT:

150

6

min(x, y, ...)

Returns the lowest-valued number in a list of numbers.

For example:

For example:

var b = Math.min(10, 150, 30, 20, 38);

OUTPUT:

10

7

pow(x, y)

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

For example:

var b = Math.pow(4, 3);

OUTPUT:64

8

random(x)

Returns a random number between 0 and 1 (including 0, but not 1).

For example:

var b = Math.random();

OUTPUT :

0.9356148595384974

9

sqrt(x)

Returns the square root of a number.

For example:

var a = Math.sqrt(0); OUTPUT :- 0

var b = Math.sqrt(1); OUTPUT :- 1

var c = Math.sqrt(9); OUTPUT :-3

var d = Math.sqrt(64); OUTPUT :-8

var e = Math.sqrt(-9); OUTPUT :-NaN

 

 

 

Comments

Popular posts from this blog

HSC BOARD ONLINE EXAM 25 HTML AND JAVASCRIPT PROGRAM LIST

HTML AND JAVASCRIPT PROGRAM

H.S.C INFORMATION TECHNOLOGY Q.8 HTML AND JAVASCRIPT PROGRAM