JavaScript Math Object

Unlike other objects, the Math object has no constructor.

The Math object is static.

All methods and properties can be used without creating a Math object first.

The syntax for any Math property is : Math.property.

JavaScript provides 8 mathematical constants that can be accessed as Math properties:

  • Math.E

  • Math.PI

  • Math.SQRT2

  • Math.SQRT1_2

  • Math.LN2

  • Math.LN10

  • Math.LOG2E

  • Math.LOG10E

Math Methods

The syntax for Math any methods is : Math.method(number)

Math.ceil(x) -> Math.ceil(x) returns the value of x rounded up to its nearest integer

example : Math.round(4.5);

Math.round(x) -> Math.round(x) returns the nearest integer

example : Math.ceil(4.9);

Math.floor(x) -> Math.floor(x) returns the value of x rounded down to its nearest integer

example : Math.floor(4.9);

Math.trunc(x) -> Math.trunc(x) returns the integer part of x

example : Math.trunc(4.9);