JavaScript Math Object JAVASCRIPT
- JavaScript Introduction
- JavaScript Syntax
- JavaScript innerHTML
- JavaScript document.write()
- Javascript - window.alert()
- JavaScript - console.log()
- JavaScript Comments
- JavaScript Variables
- JavaScript Operators
- JavaScript Data Types
- JavaScript Functions
- JavaScript Objects
- JavaScript Events
- JavaScript Strings
- JavaScript String Methods
- JavaScript Numbers
- JavaScript Number Methods
- JavaScript Arrays
- JavaScript Array Methods
- JavaScript Sorting Arrays
- JavaScript Array Iteration
- JavaScript Date Objects
- JavaScript Date Formats
- JavaScript Get Date Methods
- JavaScript Set Date Methods
- JavaScript Math Object
- JavaScript Conditions
- JavaScript Switch
- JavaScript Loop For
- JavaScript While Loop
- JavaScript Break and Continue
- JavaScript Type Conversion
- JavaScript Errors
- JavaScript Scope
- JavaScript this Keyword
- JavaScript Classes
- JavaScript Debugging
- JavaScript - Changing CSS
- JavaScript JSON
JavaScript Math Object
JavaScript - Math.PI
Math.PI
return the value of PI
JavaScript - Math.round()
Math.round(x)
returns the value of x rounded to its nearest integer.
JavaScript - Math.pow()
Math.pow(x, y)
returns the value of x to the power of y:
JavaScript - Math.sqrt()
Math.sqrt(x)
returns the square root of x.
JavaScript - Math.abs()
Math.abs(x)
returns the absolute (positive) value of x.
JavaScript - Math.ceil()
Math.ceil(x)
returns the value of x rounded up to its nearest integer.
JavaScript - Math.floor()
Math.floor(x)
returns the value of x rounded down to its nearest integer.
JavaScript - Math.sin()
Math.sin(x)
returns the sine (a value between -1 and 1) of the angle x (given in radians).
If you want to use degrees instead of radians, you have to convert degrees to radians:
Angle in radians = Angle in degrees x PI / 180.
JavaScript - Math.cos()
Math.cos(x)
returns the cosine (a value between -1 and 1) of the angle x (given in radians).
If you want to use degrees instead of radians, you have to convert degrees to radians:
Angle in radians = Angle in degrees x PI / 180.
Math.min() and Math.max()
Math.min()
and Math.max()
can be used to find the lowest or highest value in a list of arguments.
Example
Math.min(0, 150, 30, 20, -8, -200); // returns -200
Math.max(0, 150, 30, 20, -8, -200); // returns 150
JavaScript - Math.random()
Math.random()
returns a random number between 0 (inclusive), and 1 (exclusive).
Math Object Methods
Method | Description |
---|---|
abs(x) | Returns the absolute value of x |
acos(x) | Returns the arccosine of x, in radians |
asin(x) | Returns the arcsine of x, in radians |
atan(x) | Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians |
atan2(y, x) | Returns the arctangent of the quotient of its arguments |
ceil(x) | Returns the value of x rounded up to its nearest integer |
cos(x) | Returns the cosine of x (x is in radians) |
exp(x) | Returns the value of Ex |
floor(x) | Returns the value of x rounded down to its nearest integer |
log(x) | Returns the natural logarithm (base E) of x |
max(x, y, z, ..., n) | Returns the number with the highest value |
min(x, y, z, ..., n) | Returns the number with the lowest value |
pow(x, y) | Returns the value of x to the power of y |
random() | Returns a random number between 0 and 1 |
round(x) | Returns the value of x rounded to its nearest integer |
sin(x) | Returns the sine of x (x is in radians) |
sqrt(x) | Returns the square root of x |
tan(x) | Returns the tangent of an angle |