Skip to content

exponentiationOperators

Prefers the ** operator over Math.pow().

✅ This rule is included in the ts stylistic and stylisticStrict presets.

The exponentiation operator ** was introduced in ES2016 as a more readable alternative to Math.pow(). This rule suggests using ** instead of Math.pow() for exponentiation operations.

Benefits of using ** include:

  • A more concise and readable syntax
  • It works with BigInt values, unlike Math.pow()
  • Consistency with other mathematical operators
AEconsB0resuAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53MaAB0p5<3(sp ansty="le--0:#F78C6C;--1:#AA09">8<22sp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#F78C6C;--1:#AA09">8<28sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0squarAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53MaAB0p53<(xsp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#F78C6C;--1:#AA09">8<22sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0cubAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53MaAB0p53(baAE<, sp ansty="le--0:#D6DEEB;--1:#403F">53exponent<);d ivclassNa="meco"><);d>
44AEco61B0re44A0<9822 spans="tyle--0:#C792EA;--1:#88">44AE< ** spans="tyle--0:#F78C6C;--1:#AA">0<9828 spans="tyle--0:#D6DEEB;--1:#40">3<* 8><;di vdivclass="Nameexpressive-">44AEco61B0squ44A344AE< ** spans="tyle--0:#F78C6C;--1:#AA">0<9822 spans="tyle--0:#D6DEEB;--1:#40">3<* 2><;di vdivclass="Nameexpressive-">44AEco61B0c44A3F5344AE< ** spans="tyle--0:#D6DEEB;--1:#40">3F53expon

This rule is not configurable.

If you need to support environments that don’t have the exponentiation operator (pre-ES2016), you may disable this rule. However, most modern JavaScript environments support **, and transpilers can convert it for older targets.

Some projects also prefer to use Math.pow() for consistency with older codebases or Math-oriented areas of code.