JavaScript used to rely on Math.pow
for exponentiation. Oddly enough, it did not have an easy-to-write syntax for this purpose. However, the operator **
was added recently (in ECMAScript 2016 specification) to the language and it is now available in all major browsers and NodeJS.
This is how to use it:
const x = 2 ** 5 // 32
The exponentiation operator is right associative. For example, a ** b ** c
is equivalent to a ** (b ** c)
.
Note: You cannot use unary operators (+
, -
, ~
, !
, delete
, void
, typeof
) immediately before the base, because that makes the expression ambiguous.
This syntax is much easier to use than
Math.pow
. I wonder if there is a performance boost, as well.Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Good question. Probably there is a better performance, because the method call is removed.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
So, I ran a benchmark and turns out
**
is almost three times faster thanMath.pow
on NodeJS.Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
That's a very nice performance boost. It surely is an improvement.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
This post has received a 7.56 % upvote from @booster thanks to: @ghasemkiani.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
This wonderful post has received a bellyrub 6.92 % upvote from @bellyrub thanks to this cool cat: @ghasemkiani. My pops @zeartul is one of your top steemit witness, if you like my bellyrubs please go vote for him, if you love what he is doing vote for this comment as well.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
upvtd.u
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Amazing that something like this could happen!!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
grt
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Great post,thanks
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
This post UpVoted from @oliverbix
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
good pointout for new habit of writing, thanks!
upvoted
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
This post has been ranked within the top 50 most undervalued posts in the first half of Oct 20. We estimate that this post is undervalued by $28.46 as compared to a scenario in which every voter had an equal say.
See the full rankings and details in The Daily Tribune: Oct 20 - Part I. You can also read about some of our methodology, data analysis and technical details in our initial post.
If you are the author and would prefer not to receive these comments, simply reply "Stop" to this comment.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit