Lint Rules

useExponentiationOperator (since v11.0.0)

Disallow the use of Math.pow in favor of the ** operator.

Introduced in ES2016, the infix exponentiation operator ** is an alternative for the standard Math.pow function. Infix notation is considered to be more readable and thus more preferable than the function notation.

Source: https://eslint.org/docs/latest/rules/prefer-exponentiation-operator

Examples

Invalid

const foo = Math.pow(2, 8);
nursery/useExponentiationOperator.js:1:13 lint/nursery/useExponentiationOperator  FIXABLE  ━━━━━━━━━━

   Use the '**' operator instead of 'Math.pow'.
  
  > 1 │ const foo = Math.pow(2, 8);
               ^^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Use the '**' operator instead of 'Math.pow'.
  
    1  - const·foo·=·Math.pow(2,·8);
      1+ const·foo·=·2**8;
    2 2  
  
const bar = Math.pow(a, b);
nursery/useExponentiationOperator.js:1:13 lint/nursery/useExponentiationOperator  FIXABLE  ━━━━━━━━━━

   Use the '**' operator instead of 'Math.pow'.
  
  > 1 │ const bar = Math.pow(a, b);
               ^^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Use the '**' operator instead of 'Math.pow'.
  
    1  - const·bar·=·Math.pow(a,·b);
      1+ const·bar·=·a**b;
    2 2  
  
let baz = Math.pow(a + b, c + d);
nursery/useExponentiationOperator.js:1:11 lint/nursery/useExponentiationOperator  FIXABLE  ━━━━━━━━━━

   Use the '**' operator instead of 'Math.pow'.
  
  > 1 │ let baz = Math.pow(a + b, c + d);
             ^^^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Use the '**' operator instead of 'Math.pow'.
  
    1  - let·baz·=·Math.pow(a·+·b,·c·+·d);
      1+ let·baz·=·(a·+·b)**(c·+·d);
    2 2  
  
let quux = Math.pow(-1, n);
nursery/useExponentiationOperator.js:1:12 lint/nursery/useExponentiationOperator  FIXABLE  ━━━━━━━━━━

   Use the '**' operator instead of 'Math.pow'.
  
  > 1 │ let quux = Math.pow(-1, n);
              ^^^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Use the '**' operator instead of 'Math.pow'.
  
    1  - let·quux·=·Math.pow(-1,·n);
      1+ let·quux·=·(-1)**n;
    2 2  
  

Valid

const foo = 2 ** 8;

const bar = a ** b;

let baz = (a + b) ** (c + d);

let quux = (-1) ** n;