Skip to main content

$power

$power(base?, exponent) -> number
Compact type signature<n-n:n>

If base is omitted, the current context value is used.

Browse categories

Source: JSONata

Documentation

Returns the value of base raised to the power of exponent (baseexponent).

An error is thrown if the values of base and exponent lead to a value that cannot be represented as a JSON number (e.g. Infinity, complex numbers).

Examples

Basic usage

  • $power(2, 8) => 256
  • $power(2, 0.5) => 1.414213562373
  • $power(2, -2) => 0.25

Compute an exponent

Input

{
"base": 2,
"exponent": 3
}

Expression

$power(base, exponent)

Result

8