Numbers, addition, variables, and clarifications…
I’m curious why the “addition” operation {{+}} when using two numbers (non variable) results in the two numbers being added together (as expected)
- Adding two number (non variables) works as expected: 2{{+}}2=4
- Adding two numbers, one being a variable, combines the two numbers | 2+{{variable 2}}=22
- Subtraction works as expected, variable or non variable.
I’m curious why addition with numbers & variables doesn’t work as expected? (You can get the same results with SUM
eg: sum(variable;2)
.
… also just including this here for documentation reasons so if someone is looking for details on how to add a number and a variable together (using SUM function), that it’s documented somewhere.
Welcome to the Make community!
This is because Make uses JavaScript (TS?) on the backend, and it is exactly how JavaScript (programming language) will treat those variable types.
If you don’t believe me, just open up your browser console (which also uses JS) and type these in:
Numeric + String = String
Numeric + Numeric = Numeric
Numeric - (Numeric or String) = Numeric
JavaScript uses the +
operator for both Math and concatenating Strings. So when any of the variables are strings, the output is concatenated instead of summed up.
JavaScript doesn’t use the -
operator for anything other than Math, so the values are treated as Numeric. This is called Type Coercion.
What happens if you subtract a non-numeric value?
You get NaN
(not a number), basically an error.
For more information about Type Coercion on Make, see https://www.make.com/en/help/mapping/type-coercion
4 Likes