Exponent

2 snippets across 2 stacks — JavaScript, Python

JSJavaScript

Powers and Roots

JS · Numbers & Math
syntax
base ** exponent
Math.sqrt(n)
Math.cbrt(n)
Math.pow(base, exp)
example
console.log(2 ** 10);         // 1024
console.log(Math.sqrt(144));  // 12
console.log(Math.cbrt(27));   // 3
console.log(Math.abs(-42));   // 42

Note The ** operator is cleaner than Math.pow() and works with BigInt too: 2n ** 64n.

PYPython

Arithmetic Operators

PY · Numbers
syntax
+ - * / // % **
example
print(17 / 5)
print(17 // 5)
print(17 % 5)
print(2 ** 10)
output
3.4
3
2
1024

Note / always returns a float. // is floor division (rounds toward negative infinity, not toward zero). So -7 // 2 gives -4, not -3.