# JavaScript Math Object

## Math Methods

Method Description
Math.abs(x) Returns the absolute value of a number.
Math.acos(x) Returns the arccosine of a number.
Math.acosh(x) Returns the hyperbolic arccosine of a number.
Math.asin(x) Returns the arcsine of a number.
Math.asinh(x) Returns the hyperbolic arcsine of a number.
Math.atan(x) Returns the arctangent of a number.
Math.atanh(x) Returns the hyperbolic arctangent of a number.
Math.atan2(y, x) Returns the arctangent of the quotient of its arguments.
Math.cbrt(x) Returns the cube root of a number.
Math.ceil(x) Returns the smallest integer greater than or equal to a number.
Math.clz32(x) Returns the number of leading zeroes of a 32-bit integer.
Math.cos(x) Returns the cosine of a number.
Math.cosh(x) Returns the hyperbolic cosine of a number.
Math.exp(x) Returns Ex, where x is the argument, and E is Euler's constant (2.718…), the base of the natural logarithm.
Math.expm1(x) Returns subtracting 1 from `exp(x)`.
Math.floor(x) Returns the largest integer less than or equal to a number.
Math.fround(x) Returns the nearest single precision float representation of a number.
Math.hypot([x[, y[, …]]]) Returns the square root of the sum of squares of its arguments.
Math.imul(x, y) Returns the result of a 32-bit integer multiplication.
Math.log(x) Returns the natural logarithm (loge, also ln) of a number.
Math.log1p(x) Returns the natural logarithm (loge, also ln) of `1 + x` for a number x.
Math.log10(x) Returns the base 10 logarithm of a number.
Math.log2(x) Returns the base 2 logarithm of a number.
Math.max([x[, y[, …]]]) Returns the largest of zero or more numbers.
Math.min([x[, y[, …]]]) Returns the smallest of zero or more numbers.
Math.pow(x, y) Returns base to the exponent power, that is, `baseexponent`.
Math.random() Returns a pseudo-random number between 0 and 1.
Math.round(x) Returns the value of a number rounded to the nearest integer.
Math.sign(x) Returns the sign of the x, indicating whether x is positive, negative or zero.
Math.sin(x) Returns the sine of a number.
Math.sinh(x) Returns the hyperbolic sine of a number.
Math.sqrt(x) Returns the positive square root of a number.
Math.tan(x) Returns the tangent of a number.
Math.tanh(x) Returns the hyperbolic tangent of a number.
Math.toSource() Returns the string `"Math"`.
Math.trunc(x) Returns the integer part of the number x, removing any fractional digits.

## Math Methods Examples

```// Math.abs(x) returns the absolute (positive) value of x
Math.abs(-3.14);   // Returns 3.14

// Math.ceil(x) returns the value of x rounded up to its nearest integer
Math.ceil(3.14);  // Returns 4

// Math.cos(x) returns the cosine (a value between -1 and 1) of the angle x (given in radians).
// Angle in radians = Angle in degrees x PI / 180.
Math.cos(0 * Math.PI / 180);  // Returns 1 (the cos of 0 degrees)

// Math.floor(x) returns the value of x rounded down to its nearest integer
Math.floor(3.14);  // Returns 3

// Math.max() is used to find the highest value in a list of arguments
Math.max([x[, y[, �]]])
Math.min(920, 70, 30, 0, -15, -5);  // Returns 920

// Math.min() is used to find the lowest value in a list of arguments
Math.min(920, 70, 30, 0, -15, -5);  // Returns -15

// Math.pow(x, y) returns the value of x to the power of y
Math.pow(5, 2)  // Returns 25

// Math.random() returns a random number between 0 (inclusive),  and 1 (exclusive):
Math.random();  // Returns a random number

// Math.round(x) returns the value of x rounded to its nearest integer
Math.round(3.14);  // Returns 3
Math.round(3.7);   // Returns 4

// Math.sin(x) returns the sine (a value between -1 and 1) of the angle x (given in radians).
// Angle in radians = Angle in degrees x PI / 180.
Math.sin(90 * Math.PI / 180);  // Returns 1 (the sine of 90 degrees)

// Math.sqrt(x) returns the square root of x
Math.sqrt(25);  // Returns 5```

Note that the trigonometric functions (`sin()``cos()``tan()``asin()``acos()``atan()``atan2()`) expect or return angles in radians. To convert radians to degrees, divide by `(Math.PI / 180)`, and multiply by this to convert the other way.

Note that many math functions have a precision that's implementation-dependent. This means that different browsers can give a different result, and even the same JS engine on a different OS or architecture can give different results.

## Math Properties

Property Description
Math.E Euler's constant and the base of natural logarithms, approximately 2.718.
Math.LN2 Natural logarithm of 2, approximately 0.693.
Math.LN10 Natural logarithm of 10, approximately 2.303.
Math.LOG2E Base 2 logarithm of E, approximately 1.443.
Math.LOG10E Base 10 logarithm of E, approximately 0.434.
Math.PI Ratio of the circumference of a circle to its diameter, approximately 3.14159.
Math.SQRT1_2 Square root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707.
Math.SQRT2 Square root of 2, approximately 1.414.

## Check this out

### JS JavaScript: Array Sort

The sort() method in JavaScript is sorting the elements in an array and will return the sorted array. The default sort order is according to string Unicode code points.

### JS JavaScript: JavaScript Essentials

JavaScript is a scripting or programming language that allows you to implement complex things on web pages. Every time a web page does more than just sit there and display static information for you to look at, displaying timely content updates, interactive maps, animated 2D/3....

### JS JavaScript: break

The break statement terminates a current loop or a switch statement.

The continue statement "jumps over" one iteration in the current loop.

### JS JavaScript: Comparisons

Comparison and Logical operators are used to test for true or false.

JavaScript provides three different value-comparison operations, loose equality, strict equality and Object.is. They have different usage so learn when to use them.

## Need more Honney

### NDC Conferences

The NDC Conferences (Norwegian Developers Conference) are one of the world`s largest independent software conferences for .NET & Agile development. The conference covers everything you need to know within software development. The conferences are held each year in many places such as Oslo, Copenhagen, London, Sydney and Minnesota.

### Update Conference Prague

Update Conference Prague is the biggest developer conference in the Czech Republic. The conference is offering sessions delivered by the top experts from all around the world. Their goal is to inspire the attendees and enrich their knowledge.

### Troy Hunt

Learn about Web Security from Troy Hunt. He is a really engaged speaker that frequently give talks on conferences around the world. Troy is a Microsoft MVP and you can even learn from him on some great courses on Pluralsight.

### W3Schools

W3Schools.com is a great education Web Site for learning web technologies. On W3Schools you may find well organized basic to advanced tutorials and references.

### Scott Hanselman

Learn about Web Technologies and new trends from Scott Hanselman. Scott Hanselman is an author of developer books and he is an engaged speaker that usually talks about the Microsoft stack. You may meet Scott on conferences around the world.

### Developer Week

DeveloperWeek is one of the world’s largest developer conferences. Developer Week focus on new dev technologies, the conference have talks and workshops for newbies and experienced audience. You can attend on a Developer Week conference different places in Nothern America.

## Learn JavaScript Debugging

Searching for bugs and fixing them is called code debugging. The bugs might be difficult to diagnose and therefore it is important to have a good approach to find and fix the bugs effectively. Bugs in the code might be syntax errors or logical errors. Sometimes nothing happens when the code contains bugs and there is few indications where to search. Modern web browser includes a powerful suite of developer tools. The tools do a range of things...

## Explore JavaScript Arrays

Arrays are frequently used by developers. Programming languages can have slightly different implementation of arrays. An array is an object that can store a collection of items. You may say it`s a special variable that can have more than one value. The array holds many values under a single name, and you may access the values by referring to an index number. The easiest way to create....

## Ultimate Guide to HTML Colors

It is essential to give the user a good user experience. There are many things you should focus on, one of them is how you use colors on your website. We don't have to struggle with black and white TVs anymore. Users expect more and more and we can apply colors to everything we want. Texts, borders, backgrounds, shadows – in HTML they all can have whatever color you decide....

HONNEYBAG BLOG