Math Flashcards
is a built-in object that has properties and methods for mathematical constants and functions. Not a function object.
Returns the absolute value of a number
function difference(a, b) { return Math.abs(a - b); }
console.log(difference(3, 5)); // expected output: 2
console.log(difference(5, 3)); // expected output: 2
console.log(difference(1.23456, 7.89012)); // expected output: 6.6555599999999995
Returns the arccosine (in radians) of a number
// Calculates angle of a right-angle triangle in radians function calcAngle(adjacent, hypotenuse) { return Math.acos(adjacent / hypotenuse); }
console.log(calcAngle(8, 10)); // expected output: 0.6435011087932843
console.log(calcAngle(5, 3)); // expected output: NaN
Returns the hyperbolic arc-cosine of a number
console.log(Math.acosh(0.999999999999)); // expected output: NaN
console.log(Math.acosh(1)); // expected output: 0
console.log(Math.acosh(2)); // expected output: 1.3169578969248166
console.log(Math.acosh(2.5)); // expected output: 1.566799236972411
Returns the arcsine (in radians) of a number
// Calculates angle of a right-angle triangle in radians function calcAngle(opposite, hypotenuse) { return Math.asin(opposite / hypotenuse); }
console.log(calcAngle(6, 10)); // expected output: 0.6435011087932844
console.log(calcAngle(5, 3)); // expected output: NaN
Returns the hyperbolic arcsine of a number
console.log(Math.asinh(1)); // expected output: 0.881373587019543
console.log(Math.asinh(0)); // expected output: 0
console.log(Math.asinh(-1)); // expected output: -0.881373587019543
console.log(Math.asinh(2)); // expected output: 1.4436354751788103
Returns the arctangent (in radians) of a number
// Calculates angle of a right-angle triangle in radians function calcAngle(opposite, adjacent) { return Math.atan(opposite / adjacent); }
console.log(calcAngle(8, 10)); // expected output: 0.6747409422235527
console.log(calcAngle(5, 3)); // expected output: 1.0303768265243125
Returns the angle in the plane (in radians) between the positive x-axis and the ray from (0,0) to the point (x,y)
function calcAngleDegrees(x, y) { return Math.atan2(y, x) * 180 / Math.PI; }
console.log(calcAngleDegrees(5, 5)); //expected output: 45
console.log(calcAngleDegrees(10, 10)); //expected output: 45
console.log(calcAngleDegrees(0, 10)); //expected output: 90
Returns the hyperbolic arctangent of a number
console.log(Math.atanh(-1)); // expected output: -Infinity
console.log(Math.atanh(0)); // expected output: 0
console.log(Math.atanh(0.5)); // expected output: 0.549306144334055 (approximately)
console.log(Math.atanh(1)); // expected output: Infinity
Returns the cube root of a number
console.log(Math.cbrt(-1)); // expected output: -1
console.log(Math.cbrt(1)); // expected output: 1
console.log(Math.cbrt(Infinity)); // expected output: Infinity
console.log(Math.cbrt(64)); // expected output: 4
Returns the smallest integer greater than or equal to a given number.
console.log(Math.ceil(.95)); // expected output: 1
console.log(Math.ceil(4)); // expected output: 4
console.log(Math.ceil(7.004)); // expected output: 8
console.log(Math.ceil(-7.004)); // expected output: -7
Returns the number of leading zero bits in the 32-bit binary representation of a number.
// 00000000000000000000000000000001 console.log(Math.clz32(1)); // expected output: 31
// 00000000000000000000000000000100 console.log(Math.clz32(4)); // expected output: 29
// 00000000000000000000001111101000 console.log(Math.clz32(1000)); // expected output: 22
Returns the cosine of the specified angle, which must be specified in radians
function getCircleX(radians, radius) { return Math.cos(radians) * radius; }
console.log(getCircleX(1, 10)); // expected output: 5.403023058681398
console.log(getCircleX(2, 10)); // expected output: -4.161468365471424
console.log(getCircleX(Math.PI, 10)); // expected output: -10
Returns the hyperbolic cosine of a number
console.log(Math.cosh(0)); // expected output: 1
console.log(Math.cosh(1)); // expected output: 1.543080634815244 (approximately)
console.log(Math.cosh(-1)); // expected output: 1.543080634815244 (approximately)
console.log(Math.cosh(2)); // expected output: 3.7621956910836314
Returns exponent
console.log(Math.exp(0)); // expected output: 1
console.log(Math.exp(1)); // expected output: 2.718281828459 (approximately)
console.log(Math.exp(-1)); // expected output: 0.36787944117144233
console.log(Math.exp(2)); // expected output: 7.38905609893065
Returns ex - 1, where x is the argument, and e the base of the natural logarithms.
console.log(Math.expm1(0)); // expected output: 0
console.log(Math.expm1(1)); // expected output: 1.718281828459045
console.log(Math.expm1(-1)); // expected output: -0.6321205588285577
console.log(Math.expm1(2)); // expected output: 6.38905609893065