1 # Disallow the use of `Math.pow` in favor of the `**` operator (prefer-exponentiation-operator)
3 Introduced in ES2016, the infix exponentiation operator `**` is an alternative for the standard `Math.pow` function.
5 Infix notation is considered to be more readable and thus more preferable than the function notation.
9 This rule disallows calls to `Math.pow` and suggests using the `**` operator instead.
11 Examples of **incorrect** code for this rule:
14 /*eslint prefer-exponentiation-operator: "error"*/
16 const foo = Math.pow(2, 8);
18 const bar = Math.pow(a, b);
20 let baz = Math.pow(a + b, c + d);
22 let quux = Math.pow(-1, n);
25 Examples of **correct** code for this rule:
28 /*eslint prefer-exponentiation-operator: "error"*/
34 let baz = (a + b) ** (c + d);
41 This rule should not be used unless ES2016 is supported in your codebase.
45 * [MDN Arithmetic Operators - Exponentiation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Exponentiation)
46 * [Issue 5848: Exponentiation operator ** has different results for numbers and variables from 50 upwards](https://bugs.chromium.org/p/v8/issues/detail?id=5848)