A recent small project at work required me to use JavaScript, and I was surprised to find the following note in the documentation for a code that sets a timeout:
It's commonly accepted that languages like JavaScript and others will do duck typing, where a type is implied, but this seems to have gone a bit further, coercing any input into a number. My code doesn't allow user input to go into the timeout routine, so I'm not totally freaking out, but that bit of doc gave me pause. I just can't imagine a good reason to do what that does.
Like you, KV is at a loss to understand how this type of coercion is anything like duck typing.? Just to be sure, I went to find the documentation you mentioned, and what caught my eye was this:
Now, we know that the argument expected is a time, in milliseconds, and I don't know about you, but I've never seen such a time expressed as anything but an integer number—you know, like 42. Why would anyone supply anything but a number?
It also turns out that JavaScript passes a lot of strings around, or so one might think from reading this hilarious documentation. It turns out that the string "1000" is the same as the number 1,000, which is a helpful bit of coercion, but the string "1 second" gets converted to 0, because well, just because.