Arithmetic Expression
Arithmetic expressions are simple mathematical calculations, where a numeric result is returned after the expression was evaluated. They may also be chained based on their order of precedence, where each item is one by one evaluated.
Besides arithmetic expression there are also operator modified assignment, which can be used similarly by directly assigning the result to a variable.
Syntax
EXP ( + | - | * | / | ** | % ) EXP
Examples
Addition Operator
400.3 + 26.3; // -> 426.6
Minus Operator
87 - 2.5; // -> 84.5
Multiply Operator
Standard multiplications can be done between operands of the type num
.
2.4 * 5; // -> 12
Additionally, string repetitions can be also performed using the *
operator.
"Hello " * 3; // -> "Hello Hello Hello "
Divide Operator
25 / 4; // -> 6.25
Power-To Operator
2 ** 8; // -> 256
Modulo Operator
51 % 10; // -> 1