10 biggest JS pitfalls

Claude Pache claude.pache at gmail.com
Mon Dec 31 09:27:28 PST 2012

Le 31 déc. 2012 à 10:17, Axel Rauschmayer <axel at rauschma.de> a écrit :

>>> I’d be interested in other examples of implicit conversions stumping people.
>> What stumped who, when? Any bugs/github issues/blog posts to cite?
> No, I think I agree with your assessment that implicit conversion to boolean (the most prevalent implicit conversion) is manageable, possibly even desirable.
> I was interested in citations regarding non-bolean implicit conversions. So far, my impression has been that other implicit conversions either worked as people expected (+) or were never triggered (-).

Personally, I have issues with from- and to-String conversions when working with HTML form field values and data-* attributes. More precisely, I am careful to make these conversions manually, and I regret that JS doesn't warn me if I forget to do them. Indeed the following cases are problematic:

* String-to-Number : not triggered in, e.g.,  x + '1' when x is a Number.
* Boolean-to-String, Null-to-String: false and null are not converted to a falsy string.

The only would-be issue with to-Boolean conversion, is that an empty array is not falsy as in Perl or PHP, and I have to remind to be a little more lengthy (pun intended) to test empty arrays. Except that case, to-Boolean implicit conversion is not only "manageable" and "possibly even desirable" : it works without hiccup and is positively useful.


More information about the es-discuss mailing list