add
Mathematical addition of two arguments
Definition
number add(number $left, number $right)
Returns $left + $right
.
Parameters
number $left
The left argument of addition.
number $right
The right argument of addition.
Returns
number
A number equal to the value of the sum of the two parameters.
Examples
{
sum: add(`3`, `2`),
sum2: add(`3`, `-2`),
boolSum: add(`true`, `false`),
boolSum2: add(`true`, `10`),
numStringSum: add('3.1', '2.9'),
nullSum: add(`null`, `null`), // Error
textSum: add('a', 'b'), // Error
arraySum: add(`[]`, `[]`), // Error
objectSum: add(`{}`, `{}`) // Error
}
{
"sum": 5,
"sum2": 1,
"boolSum": 1,
"boolSum2": 11,
"numStringSum": 6
}
Remarks
boolean arguments are valid as well and implicitly converted to their integer values. Same holds for string arguments that follow a number format. However, it is recommended to call the function with number parameters.
Updated 12 months ago
What’s Next