Coding With Fun
Home Docker Django Node.js Articles FAQ

JavaScript Math object


May 06, 2021 JavaScript with HTML DOM Reference book


Table of contents


JavaScript Math object


Math object

Math objects are used to perform mathematical tasks.

Math objects are not classes of objects like Date and String, so there is no constructor Math().

Grammar

var x = Math.PI; Return PI
var y = Math.sqrt(16); Returns the square root of 16

Math object tutorial, refer to the JavaScript Math object tutorial on this site.


Math object properties

Property Describe
E Returns the arithmetic constant e, which is the base of the natural pair (approximately equal to 2.718).
LN2 Returns the natural pair of 2 (approximately equal to 0.693).
LN10 Returns a natural pair of 10 (approximately equal to 2.302).
LOG2E Returns a pair of es with a base of 2 (approximately equal to 1.414).
LOG10E Returns a pair of es with a base of 10 (approximately equal to 0.434).
Pi Returns the circular rate (approximately equal to 3.14159).
SQRT1_2 Returns the countdown to the square root that returns 2 (approximately equal to 0.707).
SQRT2 Returns the square root of 2 (approximately equal to 1.414).

Math object method

method describe
abs(x) Returns the absolute value of X.
acos(x) Returns the anti-hosple of X.
asin(x) Returns the intermediate of the X.
atan(x) Returns the Unti-fixed value of x between the -pi / 2 and the PI / 2 arc.
atan2(y,x) Returns an angle from the X-axis to the point (x, y) (between -Pi / 2 and Pi / 2 arc).
ceil(x) The logarithm is rounded.
cos(x) Returns the number of cosine.
exp(x) Returns E x Index.
floor(x) The round is rounded.
log(x) The natural logar of the return number (bottom E).
max(x,y,z,...,n) Returns the highest value in x, y, z, ..., n.
min(x,y,z,...,n) Returns the minimum value in x, y, z, ..., n.
pow(x,y) Returns the Y power of x.
random() Returns the random number between 0 to 1.
round(x) Take the number round into the closest integer.
sin(x) The return number of the number.
sqrt(x) The number of square meters of returns.
tan(x) Return to the angle.