JavaScript Math

The Math object in JavaScript has properties and methods for mathematical calculations. We will understand them one by one with examples.

JavaScript Math Properties

The following are some of the Math properties:

  • PI
  • SQRT2
  • LN2
  • LN10

Let us understand the properties one by one with examples.

Math.PI Property

The Math.PI property returns the ratio of a circle’s circumference to its diameter. Let us see an example to implement Math.PI Property:

Output

JavaScript Math.PI Property

Math.SQRT2 Property

The Math.SQRT2 property returns the square root of 2. Let us see an example to implement Math.SQRT2 Property:

Output

JavaScript Math.SQRT2 Property

Math.LN2 Property

The Math.LN2 property returns the natural logarithm of 2. Let us see an example to implement Math.LN2 Property:

Output

JavaScript Math.LN2 Property

Math.LN10 Property

The Math.LN2 property returns the natural logarithm of 10. Let us see an example to implement Math.LN10 Property:

Output

JavaScript Math.LN10 Property

JavaScript Math Methods

The following are some of the mathematical methods:

JavaScript Math methods

Let us understand the Math methods one by one with examples.

JavaScript abs() method

The abs() method is used to return the absolute value of a number in JavaScript. Let us see an example to implement the abs() method:

Output

JavaScript Math abs() method

JavaScript ceil() method

The ceil() method is used to return the smallest integer value, greater than or equal to a specific number. Let us see an example to implement the ceil() method:

Output

JavaScript Math ceil() method

JavaScript max() method

The max() method is used to return the maximum value from the given numbers in JavaScript. Let us see an example to implement the max() method:

Output

JavaScript Math max() method

JavaScript min() method

The min() method is used to return the minimum value from the given numbers in JavaScript. Let us see an example to implement the min() method:

Output

JavaScript Math min() method

JavaScript round() method

The round() method is used to round a given number’s value to the nearest integer. Let us see an example to implement the round() method:

Output

JavaScript Math round() method

JavaScript acos() method

The acos() method is used to return the arccosine of a specific number in radians. Let us see an example to implement the acos() method:

Output

JavaScript Math acos() method

JavaScript cos() method

The cos() method is used to return the cosine of a specific number in JavaScript. Let us see an example to implement the cos() method:

Output

JavaScript Math cos() method

JavaScript sin() method

The sin() method is used to return the sine of a specific number in radians. Let us see an example to implement the sin() method:

Output

JavaScript Math sin() method

JavaScript asin() method

The asin() method is used to return the arcsine of a specific number in radians. Let us see an example to implement the asin() method:

OutputJavaScript Math asin() method

JavaScript floor() method

The floor() method is used to return the largest integer value, smaller than or equal to a specific number. Let us see an example to implement the floor() method:

Output

JavaScript Math floor() method

JavaScript pow() method

The pow() method is used to return the base to the exponent power. Let us see an example to implement the pow() method:

Output

JavaScript Math pow() method

JavaScript sqrt() method

The sqrt() method is used to return the square root of a specific number. Let us see an example to implement the sqrt() method:

Output

JavaScript Math sqrt() method

JavaScript atan() method

The atan() method is used to return the arc tangent of a specific number in radians. Let us see an example to implement the atan() method:

Output

JavaScript Math atan() method

JavaScript tan() method

The tan() method is used to return the tangent of a specific number in JavaScript.

Let us see an example to implement the tan() method:

Output

JavaScript Math tan() method

JavaScript log() method

The log() method is used to return the natural logarithm of a specific number in JavaScript. Let us see an example to implement the log() method:

Output

JavaScript Math log() method

JavaScript random() method

The random() method is used to return a random number between 0 and 1. Here, 0 is inclusive, and 1 is exclusive. Let us see an example to implement the random() method:

Output

JavaScript Math random() method

JavaScript Booleans
JavaScript Arrays
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading