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
const result = Math.pow(2, 8);
const squared = Math.pow(x, 2);
const cubed = Math.pow(base, exponent);

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.