JavaScript math constants

In JavaScript Math is a global object with mathematical functions and constants.

Math object is extendible. for instance to make a function to calculate cuboid of a given number.
Math['cuboid'] = function(number) {
    return number * number * number
}
or defining a constant
Math['some_constant'] = value;

You can use your new function like any other function ie
console.log(Math.cuboid(3)) // returns 27
console.log(Math.some_constant) // returns value

Math.E
Euler's constant and the base of natural logarithms;
console.log(Math.E) // returns 2.718281828459045

Math.LN2
Natural logarithm of 2;
console.log(Math.LN2) // returns 0.6931471805599453

Math.LN10
Natural logarithm of 10;
console.log(Math.LN10) // returns 2.302585092994046

Math.LOG2E
Base 2 logarithm of E;
console.log(Math.LOG2E) // returns 1.4426950408889634

Math.LOG10E
Base 10 logarithm of E;
console.log(Math.LOG10E) // returns 0.4342944819032518

Math.PI
Ratio of the a circle's circumference to its diameter;
console.log(Math.PI) // returns 3.141592653589793

Math.SQRT1_2
Square root of ½ (or equivalently, 1/√2over the square root of 2);
console.log(Math.SQRT1_2) // returns 0.7071067811865476

Math.SQRT2
Square root of 2;
console.log(Math.SQRT2) // returns 1.4142135623730951

Comments

Popular posts from this blog

How to set content disposition header for nginx server to force content download

Animated daylight on HTML5 Canvas

How to make a static http server in nodejs using express

How to make a Snake Game using JavaScript and html5

JS13K Preparation