create account

The Exponentiation Operator in JavaScript by ghasemkiani

View this thread on: hive.blogpeakd.comecency.com
· @ghasemkiani · (edited)
$13.81
The Exponentiation Operator in JavaScript
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.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 137 others
properties (23)
authorghasemkiani
permlinkthe-exponentiation-operator-in-javascript
categorytechnology
json_metadata{"tags":["technology","programming","javascript","syntax"],"app":"steemit/0.1","format":"markdown","percent_steem_dollars":10000}
created2017-10-20 08:38:45
last_update2017-10-20 08:50:27
depth0
children13
last_payout2017-10-27 08:38:45
cashout_time1969-12-31 23:59:59
total_payout_value13.116 HBD
curator_payout_value0.691 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length623
author_reputation90,438,911,242,538
root_title"The Exponentiation Operator in JavaScript"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,121,636
net_rshares6,061,955,641,185
author_curate_reward""
vote details (201)
@afzaalsabir ·
upvtd.u
properties (22)
authorafzaalsabir
permlinkre-ghasemkiani-the-exponentiation-operator-in-javascript-20171020t084826503z
categorytechnology
json_metadata{"tags":["technology"],"app":"steemit/0.1"}
created2017-10-20 08:48:30
last_update2017-10-20 08:48:30
depth1
children0
last_payout2017-10-27 08:48:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7
author_reputation31,425,291,440
root_title"The Exponentiation Operator in JavaScript"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,122,261
net_rshares0
@ariak ·
$2.77
This syntax is much easier to use than `Math.pow`. I wonder if there is a performance boost, as well.
👍  
properties (23)
authorariak
permlinkre-ghasemkiani-the-exponentiation-operator-in-javascript-20171020t132143583z
categorytechnology
json_metadata{"tags":[],"app":"juya/app","format":"markdown"}
created2017-10-20 13:21:45
last_update2017-10-20 13:21:45
depth1
children3
last_payout2017-10-27 13:21:45
cashout_time1969-12-31 23:59:59
total_payout_value2.730 HBD
curator_payout_value0.037 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length101
author_reputation951,896,451,809
root_title"The Exponentiation Operator in JavaScript"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,136,039
net_rshares1,203,918,744,413
author_curate_reward""
vote details (1)
@ghasemkiani ·
Good question. Probably there is a better performance, because the method call is removed.
properties (22)
authorghasemkiani
permlinkre-ariak-re-ghasemkiani-the-exponentiation-operator-in-javascript-20171020t132143583z-20171020t132458206z
categorytechnology
json_metadata{"tags":[],"app":"juya/app","format":"markdown"}
created2017-10-20 13:24:57
last_update2017-10-20 13:24:57
depth2
children2
last_payout2017-10-27 13:24:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length90
author_reputation90,438,911,242,538
root_title"The Exponentiation Operator in JavaScript"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,136,131
net_rshares0
@ghasemkiani ·
So, I ran a benchmark and turns out `**` is almost three times faster than `Math.pow` on NodeJS.
properties (22)
authorghasemkiani
permlinkre-ghasemkiani-re-ariak-re-ghasemkiani-the-exponentiation-operator-in-javascript-20171020t132143583z-20171020t132458206z-20171020t173203268z
categorytechnology
json_metadata{"tags":[],"app":"juya/app","format":"markdown"}
created2017-10-20 17:32:15
last_update2017-10-20 17:32:15
depth3
children1
last_payout2017-10-27 17:32:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length96
author_reputation90,438,911,242,538
root_title"The Exponentiation Operator in JavaScript"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,148,464
net_rshares0
@bellyrub ·
<p>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.</p>
properties (22)
authorbellyrub
permlinkre-ghasemkiani-the-exponentiation-operator-in-javascript-20171020t084656229z
categorytechnology
json_metadata{"tags":["technology"],"app":"drotto/0.0.2"}
created2017-10-20 08:47:15
last_update2017-10-20 08:47:15
depth1
children0
last_payout2017-10-27 08:47:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length281
author_reputation7,904,765,975,109
root_title"The Exponentiation Operator in JavaScript"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,122,176
net_rshares0
@booster ·
<p>This post has received a 7.56 % upvote from @booster thanks to: @ghasemkiani.</p>
properties (22)
authorbooster
permlinkre-ghasemkiani-the-exponentiation-operator-in-javascript-20171020t084655125z
categorytechnology
json_metadata{"tags":["technology"],"app":"drotto/0.0.3rc1"}
created2017-10-20 08:47:09
last_update2017-10-20 08:47:09
depth1
children0
last_payout2017-10-27 08:47:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length85
author_reputation68,767,115,776,562
root_title"The Exponentiation Operator in JavaScript"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,122,170
net_rshares0
@chan16735 ·
grt
properties (22)
authorchan16735
permlinkre-ghasemkiani-the-exponentiation-operator-in-javascript-20171020t085444529z
categorytechnology
json_metadata{"tags":["technology"],"app":"steemit/0.1"}
created2017-10-20 08:54:45
last_update2017-10-20 08:54:45
depth1
children0
last_payout2017-10-27 08:54:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3
author_reputation306,179,440,245
root_title"The Exponentiation Operator in JavaScript"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,122,720
net_rshares0
@nicnicy ·
good pointout for new habit of writing, thanks!
upvoted
properties (22)
authornicnicy
permlinkre-ghasemkiani-the-exponentiation-operator-in-javascript-20171020t110252721z
categorytechnology
json_metadata{"tags":["technology"],"app":"steemit/0.1"}
created2017-10-20 11:02:57
last_update2017-10-20 11:02:57
depth1
children0
last_payout2017-10-27 11:02:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length55
author_reputation1,091,889,471,875
root_title"The Exponentiation Operator in JavaScript"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,130,989
net_rshares0
@oliverbix ·
This post UpVoted from @oliverbix https://resmim.net/f/03mP5b.png
https://resmim.net/f/rmGxrN.gif
properties (22)
authoroliverbix
permlinkre-ghasemkiani-the-exponentiation-operator-in-javascript-20171020t103351407z
categorytechnology
json_metadata{"tags":["technology"],"users":["oliverbix"],"image":["https://resmim.net/f/03mP5b.png","https://resmim.net/f/rmGxrN.gif"],"app":"steemit/0.1"}
created2017-10-20 10:33:57
last_update2017-10-20 10:33:57
depth1
children0
last_payout2017-10-27 10:33:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length97
author_reputation1,339,239,805,340
root_title"The Exponentiation Operator in JavaScript"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,129,184
net_rshares0
@parthakp ·
Amazing that something like this could happen!!
properties (22)
authorparthakp
permlinkre-ghasemkiani-the-exponentiation-operator-in-javascript-20171020t085256552z
categorytechnology
json_metadata{"tags":["technology"],"app":"steemit/0.1"}
created2017-10-20 08:53:06
last_update2017-10-20 08:53:06
depth1
children0
last_payout2017-10-27 08:53:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length47
author_reputation353,898,378,454
root_title"The Exponentiation Operator in JavaScript"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,122,582
net_rshares0
@saharukhsk ·
Great post,thanks
properties (22)
authorsaharukhsk
permlinkre-ghasemkiani-the-exponentiation-operator-in-javascript-20171020t090752439z
categorytechnology
json_metadata{"tags":["technology"],"app":"steemit/0.1"}
created2017-10-20 09:08:15
last_update2017-10-20 09:08:15
depth1
children0
last_payout2017-10-27 09:08:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length17
author_reputation5,892,714,147
root_title"The Exponentiation Operator in JavaScript"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,123,618
net_rshares0
@screenname ·
Re: The Exponentiation Operator in JavaScript
<p>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.</p> 
<p>See the full rankings and details in <a href="https://steemit.com/curation/@screenname/the-daily-tribune-most-undervalued-posts-of-oct-20---part-i">The Daily Tribune: Oct 20 - Part I</a>. You can also read about some of our methodology, data analysis and technical details in <a href="https://steemit.com/curation/@screenname/introducing-the-daily-tribune-most-undervalued-posts-of-nov-04---part-i">our initial post</a>.</p>
<p>If you are the author and would prefer not to receive these comments, simply reply "Stop" to this comment.</p>
properties (22)
authorscreenname
permlinkre-the-exponentiation-operator-in-javascript-20171020t133901
categorytechnology
json_metadata"{"replyto": "@ghasemkiani/the-exponentiation-operator-in-javascript"}"
created2017-10-20 13:39:03
last_update2017-10-20 13:39:03
depth1
children0
last_payout2017-10-27 13:39:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length763
author_reputation46,276,338,038,330
root_title"The Exponentiation Operator in JavaScript"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,136,473
net_rshares0