o9s
is a microblog
home archives search feed blogroll


The Exponentiation Operator

Coming soon in ES7 (probably).

5 ** 2; // 25
5 ** 3; // 125

let value = 2;
value **= 3; // 8

No Math.pow required. It’s not a new concept. Python, Ruby, Perl and PHP use the same operator. MATLAB and R use the ^ operator.

It allows for a shorter syntax, which seems to be what JavaScript has been all about lately.

It’s already usable with Babel.

npm install --save-dev babel-plugin-transform-exponentiation-operator

And in .babelrc:

{
  "plugins": ["transform-exponentiation-operator"]
}
Posted on 2018-01-13   #javascript  






← Next post    ·    Previous post →