Is the double asterisk ** a valid JavaScript operator?

后端 未结 3 583
我寻月下人不归
我寻月下人不归 2021-01-03 17:52

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

相关标签:
3条回答
  • 2021-01-03 18:09

    ** 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)
    
    0 讨论(0)
  • 2021-01-03 18:11

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

    Here are the details from Wikipedia.

    Two new features added in ES7:

    the exponentiation operator (**) and Array.prototype.includes

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

    You can play with this in this Babel Live compiler

    0 讨论(0)
  • 2021-01-03 18:14

    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.

    0 讨论(0)
提交回复
热议问题