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
const result: number
result
=
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.pow(x: number, y: number): number

Returns the value of a base expression taken to a specified power.

@paramx The base value of the expression.

@paramy The exponent value of the expression.

pow
(2, 8);
const
const squared: number
squared
=
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.pow(x: number, y: number): number

Returns the value of a base expression taken to a specified power.

@paramx The base value of the expression.

@paramy The exponent value of the expression.

pow
(
const x: any
x
, 2);
const
const cubed: number
cubed
=
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.pow(x: number, y: number): number

Returns the value of a base expression taken to a specified power.

@paramx The base value of the expression.

@paramy The exponent value of the expression.

pow
(
const base: any
base
,
const exponent: any
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 ❤️‍🔥 around the world by the Flint team and contributors.