It makes sense in that it's a well-defined behavior, but you would never actually want that behavior. You'd be far more likely to do something like that accidentally, but since JS likes to do implicit type conversions you wouldn't necessarily notice that you'd made a mistake. Far better to get a type error and a stack trace so you know you've made a mistake and find the exact line it's caused by.
Well, I'm strictly in favour of statically typed languages, so IMO all this runtime dicking around is just a source for bugs and additional testing. Much better to have your compiler tell you that you're an idiot before the code ever runs.
4
u/bra_c_ket Aug 26 '20
It makes sense in that it's a well-defined behavior, but you would never actually want that behavior. You'd be far more likely to do something like that accidentally, but since JS likes to do implicit type conversions you wouldn't necessarily notice that you'd made a mistake. Far better to get a type error and a stack trace so you know you've made a mistake and find the exact line it's caused by.