JAVASCRIPT NATIVE OBJECT-MATH OBJECT PAGE(2)

Math Methods:
1.     Math.abs(x)-  Returns the absolute value of a number.
Syntax:     Math.abs( x ) ;
Example:
<script type="text/javascript">
 var value = Math.abs(-1);
document.write("First  Value : " + value ); 
  var value = Math.abs(null);
document.write("<br />Second Value : " + value ); 
 var value = Math.abs(20);
document.write("<br />Third  Value : " + value ); 
 var value = Math.abs("string");
document.write("<br />Fourth  Value : " + value ); 
</script>

Output:   
First  Value : 1
Second Value : 0
Third  Value : 20
Fourth  Value : NaN   

2.Math.cos(x)- Returns the cosine of a number.
Syntax: Math.cos(x);
Example: Math.cos(3);
Output: -0.9899924966004454

3.Math.sin(x)- Returns the sine of a number.
Syntax: Math.sin(x)
Example: Math.sin(3);
Output: 0.1411200080598672
4.Math.tan(x)- Returns the tangent of a number.
Syntax: Math.tan(x)
Example: Math.tan(90);
Output: -1.995200412208242
5.Math.sqrt(x)- Returns the positive square root of a number.
Syntax: Math.sqrt(x)
Example: Math.sqrt(9);
Output:3
6.Math.sign(x)- Returns the sign of the x, indicating whether x is positive, negative or zero.
Syntax: Math.sign(x)
Example                       Output
Math.sign(3)                  1
Math.sign(-3)                 -1
Math.sign(0)                  0
Math.sign(“tea”)             NaN
7.Math.trunc(x)- Returns the integral part of the number x, removing any fractional digits.
Syntax:Math.trunc(x)
Example:                  Output
Math.trunc(13.37)      13
Math.trunc(42.84)       42
Math.trunc(0.123)       0
Math.trunc(“-1.123”)     -1
Math.trunc(NaN)           NaN
8.Math.round(x)- Returns the value of a number rounded to the nearest integer.
Syntax: Math.round(x)
Example: Math.round(2.5);
Output:3
9.Math.random()-Returns a pseudo-random number between 0 and 1.
Syntax: Math.random();
Example: Math.random();
Output: 0.4595400223042816
10.Math.pow(x,y)- Returns base to the exponent power, that is, baseexponent.
Syntax: Math.pow(x,y)
Example: Math.pow(4, 3);
Output:64
11.Math.min([x[,y[,…..]]])-Returns the smallest of zero or more numbers
Syntax: Math.min([x[,y[,…..]]])
Example: Math.min(5, 10);
Output:5
12.Math.max([x[,y[,….]]])-Returns the largest of zero or more numbers
Syntax: Math.max([x[,y[,….]]])
Example: Math.max(5, 10);
Output:10
13.  Math.log(x)- Returns the natural logarithm (loge, also ln) of a number.
Syntax: Math.log(x)
Example: Math.log(2);
Output: 0.6931471805599453
14.Math.ceil(x)- Returns the smallest integer greater than or equal to a number.
Syntax: Math.ceil(x)
Example: Math.ceil(1.4)
Output:2
15.Math.exp(x)- Returns Ex, where x is the argument, and E is Euler's constant (2.718...), the base of the natural logarithm.
Syntax: Math.exp(x)
Example: Math.exp(1);
Output: 2.718281828459045
16.Math.floor(x)- Returns the largest integer less than or equal to a number.
Syntax: Math.floor(x)
Example: Math.floor(1.6);
Output:1
17.Math.log10(x)- Returns the base 10 logarithm of x.
Syntax: Math.log10(x)
Example: Math.log10(2)
Output:0.301
18.Math.log2(x)- Returns the base 2 logarithm of x.
Syntax: Math.log2(x)
Example: Math.log2(2)
Output:1

No comments:

Post a Comment