How do you do exponents in JavaScript?
Like how would you do 12^2?
To get the exponent power of a number, use the Math. pow (base, exponent ) method. This method returns the base to the exponent power, that is, base exponent.
pow() function returns the base to the exponent power, as in base exponent , the base and the exponent are in decimal numeral system.
Square a number using Math.By using the Math. pow() method, you can easily find the square of a number by passing the number 2 as your exponent parameter. And that's how you find the square of a number using Math. pow() method.
Math.pow()
:
js> Math.pow(12, 2)
144
There is an exponentiation operator, which is part of the ES7 final specification. It is supposed to work in a similar manner with python and matlab:
a**b // will rise a to the power b
Now it is already implemented in Edge14, Chrome52, and also it is available with traceur or babel.
Math.pow(base, exponent)
, for starters.
Example:
Math.pow(12, 2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With