
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.
解决方案
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.
博客探讨了JavaScript中双星号(**)作为指数运算符的使用,该运算符在ECMAScript2016(ES7)中被引入,等同于Math.pow函数。作者在CodeWars上发现了一个解决方案,其中使用了这个运算符,并对其在不同环境下的兼容性产生了疑问。解决方案确认**是有效的,并提供了详细解释。

被折叠的 条评论
为什么被折叠?



