3 ms·
If we are being pedantic, what is going on here is not type coercion. If it were type coercion, we would expect the add function to have either of these two be
by firebacon 8y ago
If we are being pedantic, what is going on here is not type coercion.
If it were type coercion, we would expect the add function to have either of these two behaviours:
- coerce the input arguments to strings, i.e. implicitly accept two strings and return another string
- coerce the input arguments to integers, i.e. implicitly accept two integers and return an integer
However, that is not what is happening here.
Of course, in Javascript it is implemented as a function that takes the theoretical "Any" type and decides what do do at runtime. But in a statically type language, the equivalent mechanism would be dynamic/multiple dispatch (or a static overload, possibly in combination with a generic/template method) -- not type coercion.