Languages
[Edit]
EN

Uncaught SyntaxError: Unary operator used immediately before exponentiation expression. Parenthesis must be used to disambiguate operator precedence - Google Chrome

1 points
Created by:
JustMike
26120

1. Problem

This code:

// ONLINE-RUNNER:browser;

console.log( -2 ** 4 ); // Syntax error!

Throws exception:

Uncaught SyntaxError: Unary operator used immediately before exponentiation expression. Parenthesis must be used to disambiguate operator precedence

2. Solution

If base value is negative it should be placed in brackets.

In our case we have -2, so we put it into brackets, like this: ( -2 ) and it solves the problem.

Example:

// ONLINE-RUNNER:browser;

console.log( (-2) ** 4 ); // 16

See also

  1. JavaScript - Math.pow() method example
Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join