Hello guys! morning to you all and welcome to my new tutorial post on JavaScript. In my last tutorial post, we rounded up our tutorial on Date Object. Now in this tutorial, we are going to be discussing about JavaScript Math Object.
The math object provides you with properties and methods for mathematical constants and functions. Unlike other global objects, Math is not a constructor. All the properties and also the methods of Math are static and can be called by using Math as an object without even creating it.
Thus, you refer to the constant pi as Math.PI and you call the sine function as Math.sin(x), where x is the method's argument.
The math object provides you with properties and methods for mathematical constants and functions. Unlike other global objects, Math is not a constructor. All the properties and also the methods of Math are static and can be called by using Math as an object without even creating it.
Thus, you refer to the constant pi as Math.PI and you call the sine function as Math.sin(x), where x is the method's argument.
Syntax
The syntaxes to call the properties and methods of a Math object are as follows 
var pi_val = Math.PI;
var sine_val = Math.sin(30);
var sine_val = Math.sin(30);
You can also read our tutorial post on: Static Methods in JavaScript  Learn with well explained examples
Math Properties
Below is a list of all the properties of Math and their description.
Sr.No.  Property & Description 

1  E \
Euler's constant and the base of natural logarithms, approximately 2.718.

2  LN2
Natural logarithm of 2, approximately 0.693.

3  LN10
Natural logarithm of 10, approximately 2.302.

4  LOG2E
Base 2 logarithm of E, approximately 1.442.

5  LOG10E
Base 10 logarithm of E, approximately 0.434.

6  PI
Ratio of the circumference of a circle to its diameter, approximately 3.14159.

7  SQRT1_2
Square root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707.

8  SQRT2
Square root of 2, approximately 1.414.

In the subsequent tutorials, we will be making use of few examples to demonstrate the usage of Math properties.
You can also read our tutorial post on: Learn about the 19 important JavaScript String Methods you should know with proper examples
Math Methods
Below is a list of all the methods of Math object and their description
Sr.No.  Method & Description 

1  abs()
Returns the absolute value of a number.

2  acos()
Returns the arccosine (in radians) of a number.

3  asin()
Returns the arcsine (in radians) of a number.

4  atan()
Returns the arctangent (in radians) of a number.

5  atan2()
Returns the arctangent of the quotient of its arguments.

6  ceil()
Returns the smallest integer greater than or equal to a number.

7  cos()
Returns the cosine of a number.

8  exp()
Returns EN, where N is the argument, and E is Euler's constant, the base of the natural logarithm.

9  floor()
Returns the largest integer less than or equal to a number.

10  log()
Returns the natural logarithm (base E) of a number.

11  max()
Returns the largest of zero or more numbers.

12  min()
Returns the smallest of zero or more numbers.

13  pow()
Returns base to the exponent power, that is, base exponent.

14  random()
Returns a pseudorandom number between 0 and 1.

15  round()
Returns the value of a number rounded to the nearest integer.

16  sin()
Returns the sine of a number.

17  sqrt()
Returns the square root of a number.

18  tan()
Returns the tangent of a number.

19  toSource()
Returns the string "Math".

In the subsequent tutorials, we will be using few examples to demonstrate the proper usage of these methods associated with Math object.
You can also read our tutorial post on: Steps on how to implement JavaScript Nested functions with examples
Alright guys, we have come to the end of this tutorial post. In my next tutorial, i will use some examples to explain the proper usage of the Math properties.
Follow us on our various social media handles to stay updated with our latest tutorials. Thanks for reading and bye for now.
Follow us on our various social media handles to stay updated with our latest tutorials. Thanks for reading and bye for now.
0 comments:
Post a Comment
Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.