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
28150

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
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join