4 ms·
Even JavaScript, which is much maligned for it's poor implementation of dynamic typing, has clear rules for type coercion. In the author's example in support o
by hawleyal 12y ago
Even JavaScript, which is much maligned for it's poor implementation of dynamic typing, has clear rules for type coercion.
In the author's example in support of "Variables should not be allowed to change their type," the variable "x" is subject to coercion, but the real problem was poor scoping by using the global value instead of the parameter.
This would be the same scoping problem, even if the variable type was not changed. Any non-deterministic function that modifies existing state can be said to produce unexpected/unpredictable/unreasonable results. In this case, the unpredictability was not due to a variable changing type.