Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript exponents

How do you do exponents in JavaScript?

Like how would you do 12^2?

like image 263
McKayla Avatar asked May 06 '11 05:05

McKayla


People also ask

How do you do exponents in JavaScript?

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.

What does POW () mean in JavaScript?

pow() function returns the base to the exponent power, as in base exponent , the base and the exponent are in decimal numeral system.

How do you square in JavaScript?

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.


3 Answers

Math.pow():

js> Math.pow(12, 2)
144
like image 165
Ignacio Vazquez-Abrams Avatar answered Oct 18 '22 03:10

Ignacio Vazquez-Abrams


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.

like image 64
Salvador Dali Avatar answered Oct 18 '22 04:10

Salvador Dali


Math.pow(base, exponent), for starters.

Example:

Math.pow(12, 2)
like image 25
Tieson T. Avatar answered Oct 18 '22 03:10

Tieson T.