Skip to content

math/prefer-exponentiation-operator

enforce the use of exponentiation (**) operator instead of other calculations

  • 🔧 The --fix option on the command line can automatically fix some of the problems reported by this rule.
  • 💡 Some problems reported by this rule are manually fixable by editor suggestions.

📖 Rule Details

This rule aims to enforce the use of exponentiation (**) operator instead of other calculations.

The exponentiation operator (**) provides several advantages over alternatives:

  • Readability: More concise and mathematically intuitive
  • Performance: Often better optimized by JavaScript engines
  • Consistency: Standard ES2016+ syntax for exponentiation
  • Type Safety: Better behavior with edge cases compared to Math.pow

This rule was inspired by ESLint Core's prefer-exponentiation-operator, but additionally detects multiplication with the same operands.

Now loading...

🔧 Options

Nothing.

📚 Further reading

🚀 Version

This rule was introduced in eslint-plugin-math v0.6.0

🔍 Implementation