JS: Power and Roots
Power and Roots
Math.pow(x, y)-
- x raised to the power of y.
- Same as
x ** y.
console.log(Math.pow(2, 3)); // 8 console.log(2 ** 3); // 8 Math.sqrt(x)-
Square root.
console.log(Math.sqrt(4)); // 2 console.log(Math.sqrt(9)); // 3 Math.cbrt(x)-
(new in ECMAScript 2015)
Cube root.
console.log(Math.cbrt(8)); // 2 console.log(Math.cbrt(27)); // 3
To compute nth root, use Math.pow(x, 1/n).
JavaScript. math functions.
- JS: Math (namespace)
- JS: Math. max, min
- JS: Math. sign, abs
- JS: Math ceiling, floor, round, truncate
- JS: Math. random
- JS: Power and Roots
- JS: Math exponential and logarithm
- JS: Math constants. pi, e, sqrt, etc.
- JS: Math trig functions. sin, cos, tan, asin, acos, atan
- JS: Math hyperbolic functions. sinh, cosh, tanh, etc.
- JS: Math fround, clz32, imul