Javascript Math Object

In Javascript Math object provides veriety of methods or function and properies that can be used to easily do mathematical calculations. Math object is an in built object and so it is not required to instantiate the object as done for Date object.

Unlike the other global objects, Math is not a constructor. All properties and methods of Math are static.

Syntax

Here is the simple syntax to call properties and methods of Math.

<html>
<head>
<title>Javascript Math Object</title>
var log_val = Math.LOG10E;
var sine_val = Math.sin(10);
</head>
<body>
</body>
</html>

Math Properties

Here is a list of each math property with description.

PropertyDescription
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.
LOG10E 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.

Math Methods

Here is a list of each method of math object with description.

MethodDescription
abs()This will returns the absolute value of a number.
acos() This will returns the arccosine (in radians) of a number.
asin() This will returns the arcsine (in radians) of a number.
atan() This will returns the arctangent (in radians) of a number.
atan2() This will returns the arctangent of the quotient of its arguments.
ceil()This will returns the smallest integer greater than or equal to a number.
cos() This will returns the cosine of a number.
exp() This will returns EN, where N is the argument, and E is Euler's constant, the base of the natural logarithm.
floor()This will returns the largest integer less than or equal to a number.
log() This will returns the natural logarithm (base E) of a number.
max()This will returns the largest of zero or more numbers.
min() This will returns the smallest of zero or more numbers.
pow() This will returns base to the exponent power, that is, base exponent.
random()This will returns a pseudo-random number between 0 and 1.
round() This will returns the value of a number rounded to the nearest integer.
sin()This will returns the sine of a number.
sqrt()This will returns the square root of a number.
tan()This will returns the tangent of a number.

Math Example

<DOCTYPE html>
<html> 
<TITLE>Example of Number Object</TITLE>
<head> 
<SCRIPT LANGUAGE="JavaScript">
document.write(Math.round(7.25));
document.write("</br>");
document.write(Math.random());
document.write("</br>");
var no=Math.random()*10
document.write(Math.floor(no))
document.write("</br>");
document.write(Math.max(2,4))
document.write("</br>");
document.write(Math.min(2,4))
document.write("</br>");
document.write(Math.ceil(4.4));         
document.write("</br>");
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
Try Now

See Also

Javascript Built in String Object
Javascript Built in Number Object
Javascript Built in Math Object
Javascript Built in Date Object
Javascript Built in Arrays Object
Javascript Built in Boolean Object
Javascript Built in RegExp Object
Javascript Built in JSON Object


 
SHARE THIS IF YOU LIKE!
submit to reddit
SUBSCRIBE FOR LATEST UPDATES
HAVE WE CONNECTED ON FACEBOOK?
TOP TUTORIALSTOP CODE EXAMPLESTOP LIVE DEMOLINKSSTAY CONNECTED
HTML Tutorial
HTML5 Tutorial
Bootstrap3 Tutorial
Javascript Tutorial
TypeScript Tutorial
AngularJS Tutorial
CSharp Tutorial
PHP Tutorial
Developer Tools
Javascript
AngularJS
Google MAP API V3
ASP.NET
Javascript
AngularJS
Google MAP API V3
Contact Us
Advertise with Us
Privacy Policy
Disclaimer
Stay connected. We actually like you. If you want to get up to the minute updates, then connect with us on your fav below.
 
Twitter   Linkedin   Facebook   Google+    RSS   Pinterest
 
Protected by Copyscape Original Content Checker
 
 
Copyright ©2017 www.techstrikers.com Unauthorized reproduction/replication of any part of this site is prohibited.