src/content/docs/linter/rules/use-exponentiation-operator.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/style/useExponentiationOperator`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`prefer-exponentiation-operator`](https://eslint.org/docs/latest/rules/prefer-exponentiation-operator) - Same as [`e18e/prefer-exponentiation-operator`](https://github.com/e18e/eslint-plugin){
"linter": {
"rules": {
"style": {
"useExponentiationOperator": "error"
}
}
}
}
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.
const foo = Math.pow(2, 8);
const bar = Math.pow(a, b);
let baz = Math.pow(a + b, c + d);
let quux = Math.pow(-1, n);
const foo = 2 ** 8;
const bar = a ** b;
let baz = (a + b) ** (c + d);
let quux = (-1) ** n;