JavaScript – Math

The Math object allows you to perform mathematical tasks.
All properties/methods of Math can be called by using Math as an object, without creating it.

The code:

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var x=9;
var y=Math.sqrt(x);
document.getElementById("demo").innerHTML=y;
</script>

</body>
</html>

Notice:

x=9;
y=Math.sqrt(x);

Complete list:


var y=Math.abs(x)		// Returns the absolute value of x

var y=Math.acos(x)		// Returns the arccosine of x, in radians

var y=Math.asin(x)		// Returns the arcsine of x, in radians

var y=Math.atan(x)		// Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians

var y=Math.atan2(y,x)		// Returns the arctangent of the quotient of its arguments

var y=Math.ceil(x)		// Returns x, rounded upwards to the nearest integer

var y=Math.cos(x)		// Returns the cosine of x (x is in radians)

var y=Math.exp(x)		// Returns the value of Ex

var y=Math.floor(x)		// Returns x, rounded downwards to the nearest integer

var y=Math.log(x)		// Returns the natural logarithm (base E) of x

var y=Math.max(x,y,z,...,n)	// Returns the number with the highest value

var y=Math.min(x,y,z,...,n)	// Returns the number with the lowest value

var y=Math.pow(x,y)		// Returns the value of x to the power of y

var y=Math.random()		// Returns a random number between 0 and 1

var y=Math.round(x)		// Rounds x to the nearest integer

var y=Math.sin(x)		// Returns the sine of x (x is in radians)

var y=Math.sqrt(x)		// Returns the square root of x

var y=Math.tan(x)       	// Returns the tangent of an angle

My official WebSite >