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.
Code
// ** 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: 8How 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
Number Base ConverterConvert arbitrary-size integers between binary, octal, decimal, hexadecimal, and base 36 with digit validation and signed input support.Number to WordsConvert an integer up to 999,999,999,999 into US English words, using the short scale and a minus prefix for negative values.Roman Numeral ConverterConvert integers between 1 and 3999 to Roman numerals and back, rejecting malformed numeral forms.Scientific Notation ConverterConvert numbers between plain decimal and scientific notation, optionally fixing the significant digits and splitting out the mantissa and exponent.
FAQ
- What has to be installed first?
- Nothing — the runtime itself provides everything the code touches. Its state lives in module-level bindings: `depth`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.