Is double asterisk ** valid Javascript operator?

I solved the kata on the codes and looked through some other solutions when I came across a double asterisk to indicate its strength. I did some research and see that this is the correct statement in python, but does not see anything in the JavaScript documentation.

var findNb = m => { var n = Math.floor((4*m)**.25); var sum = x => (x*(x+1)/2)**2; return sum(n) == m ? n : -1; } 

However, when I run this solution on code tables, it works. I am wondering if this is new in ES6, although I have not found anything about it.

+6
source share
3 answers

Yes. ** is an exponentiation operator and is the equivalent of Math.pow .

It was introduced in ECMAScript 2016 (ES7).

See the proposal and this chapter of ES2016 Study for more details.

+17
source

** was introduced in ECMAScript 2016 (ES7). But keep in mind that not all javascripts implement it (for example, Internet Explorer does not support it).

If you want to be a cross browser, you should use Math.pow .

 Math.pow(4, 5) 
+8
source
Operator

** is a valid operator in ES7. It has the same meaning as Math.pow(x,y) For example, 2**3 matches Math.pow(2,3)

Here are the details from Wikipedia.

ES7 added two new features:

exponential operator (**) and Array.prototype.includes

https://en.wikipedia.org/wiki/ECMAScript#cite_ref-ES2016_12-1

You can play with this in this Buel Live Compiler

+1
source

All Articles