forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 2
JS Math Pow
Quincy Larson edited this page Aug 20, 2016
·
1 revision
The Math.pow() returns the base
to the exponent
power.
Math.pow(base, exponent);
base
The base number
exponent
The exponent with which to raise the base number.
.pow() is a static method of the Math object, so you must always use it as Math.pow()
// Simple exponents
Math.pow(2, 2); // 4
Math.pow(2, 3); // 8
Math.pow(2, 10); // 1024
//Fractional exponents
Math.pow(9, 0.5); // 3 (the square root of 9)
Math.pow(24, 1/3); // 8 (the cubed root of 24)
//Signed exponents
Math.pow(5, -2); // .04 (1/25)
//Signed bases
Math.pow(-5, 2); // 25 (squares are positive)
Math.pow(-5, 3); // -125 (cubes can be negative)
Math.pow(-5, 0.5); // NaN because negative numbers don't have a real square root
//Due to limits in the precision of floating point numbers,
//a negative base with a fractional exponent will always return NaN
Math.pow(-5, 1/2); // NaN
Source MDN
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links