Exponentiation Binds Right And Overflows

The ** operator matches Math.pow, groups right-to-left so 2 ** 3 ** 2 is 512, accepts fractional exponents, and overflows past double range into Infinity.

JavascriptData Integrity

Code

javascriptsnippet
19 lines
// ** is equivalent to Math.pow
console.log('2 ** 10:', 2 ** 10);
console.log('Math.pow:', Math.pow(2, 10));

// right-associative: the right-hand exponent is evaluated first
console.log('2 ** 3 ** 2:', 2 ** 3 ** 2);
console.log('(2 ** 3) ** 2:', (2 ** 3) ** 2);

// negative and fractional exponents are both supported
console.log('2 ** -2:', 2 ** -2);
console.log('9 ** 0.5:', 9 ** 0.5);

// a result beyond the double range becomes Infinity
console.log('1e200 ** 2:', 1e200 ** 2);

// **= updates in place
let depth = 2;
depth **= 3;
console.log('depth:', depth);

Output

Captured from a sandboxed run of this snippet in the build pipeline.

2 ** 10: 1024
Math.pow: 1024
2 ** 3 ** 2: 512
(2 ** 3) ** 2: 64
2 ** -2: 0.25
9 ** 0.5: 3
1e200 ** 2: Infinity
depth: 8

How it works

Top-level bindings depth hold the demo state — nothing sits inside a function scope.

What to watch for

  • The whole dependency story is the language version itself.

Putting it to use

Output lines are prefixed (2 ** 10:, Math.pow:, 2 ** 3 ** 2:), making the effect of each step easy to see.

The core lines of the flow

let depth = 2;
depth **= 3;

Interactive Tools for This Topic

FAQ

What has to be installed first?
Nothing — the runtime itself provides everything the code touches. Its state lives in module-level bindings: `depth`.