I solved a kata on CodeWars and was looking through some of the other solutions when I came across the double asterisk to signify to the power of. I have done some research and can see that this is a valid operator in python but can see nothing about it in 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; }
Yet when I run this solution on CodeWars, it seems to work. I am wondering if this is new in ES6, although I have found nothing about it.
Double Asterisks (**) — Exponentiationpow(x, y) , which is equal to x^y. Many of you might have used Math. pow only when needed.
In a function definition, the double asterisk is also known **kwargs. They used to pass a keyword, variable-length argument dictionary to a function. The two asterisks (**) are the important element here, as the word kwargs is conventionally used, though not enforced by the language.
The exponentiation operator ( ** ) returns the result of raising the first operand to the power of the second operand. It is equivalent to Math. pow , except it also accepts BigInts as operands.
Yes. **
is the exponentiation operator and is the equivalent of Math.pow
.
It was introduced in ECMAScript 2016 (ES7).
For details, see the proposal and this chapter of Exploring ES2016.
**
was introduced in ECMAScript 2016 (ES7). But keep in mind that not all javascripts environments implements it (for instance, Internet Explorer does not support it).
If you want to be cross browser, you have to use Math.pow
.
Math.pow(4, 5)
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