Re:JavaScript Coercions Grid
by tuesdayrain on Saturday March 30, 2019 @10:26AM
(#19529563)
I'm not entirely sure why all of this even exists, it seems like it creates a lot of potential for bugs. I've been developing in JS for years and I've never intentionally used type coercion. If I ever needed to operate on multiple types I would always explicitly cast them to the correct type beforehand.
[ Parent
| on HN ]
I think it's mostly just backwards compatibility at this point; unlike with server-side languages, you can't just bump the major version and let people switch to it at their own pace. No browser is motivated to make breaking changes because there's a chance that they could break existing sites, and from a user's perspective, all they'll see is that site Foo works in Browser A but not Browser B, so Browser A will presumably lose some market share.
>unlike with server-side languages, you can't just bump the major version and let people switch to it at their own pace.
That's what strict mode was for.
I'm not super knowledgeable about JS, but my guess is that most of the stuff described in the article probably don't happen under strict mode, right?
Correct.
Using variables in Boolean expressions (to check whether the value exists) is the one place I (and probably most JS developers) use type coercion. Which can still bite you, especially if you have a zero that you expect to be considered a present value.