Skip to main content

Command Palette

Search for a command to run...

JavaScript Math Object

Published
•1 min read•View as Markdown
JavaScript Math Object
S

A passionate Full Stack Software Developer 🚀 having an experience of building Web applications with JavaScript and some other cool libraries and frameworks.

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);

More from this blog

Shubham's blog

66 posts