ES7 Exponentiation Operator
exponentiation operator is one of minor feature introduced in EcmaScript2017(ES7) language.
It applies two asterick symbols
** on two operands which returns the result of first operand to power of second operand.
- These is replacement of
Math.pow(m,n)function in Math library
- used in arthmatic,scientifical and 3D calculations
- Both operands are variables or constants
- right associative ie right to left, applied when multiple exponentional operators are used
- Shorter syntax for power of values.
Syntax of exponetiation operator
Operand1 ** Operand2 which is equal to Operand1 power of Operand2
Operand1 is called as
Operand2 is called as
5***3 is equal to
5 power of 3 is equal to
Some of the valid and invalid examples are seen below
Binary operator, Unary opeartor is not allowed
Unary operators like +,-,delete and void are not allowed for base
+2 **4 -2** 5
The above code results compilation error unknown: Illegal expression. Wrap left hand side or entire exponentiation in parentheses.
exponent NAN,null,undefined values
- applying any operator on NAN as exponent results always NAN.
- null will treat as zero and apply null results to 1
- undefined exponent results NAN
2 ** NAN //NAN 2 ** undefined //NAN 2 ** null // 1