> How many of these can you correctly predict the result of? Knowing Gijs, I know the answer is "all of them" :)
This is certainly a factor in this discussion - how familiar you are with JS, and how much you use it every day, certainly affects your perspective. Gijs' (and my) experience is that using "===" instead of "==" doesn't actually solve a lot of problems in practice. At least not for our project or our team. That being said, I don't think there is a strong argument against using "===" consistently, and it very well may help avoid trip-ups in some cases, particularly with those not as familiar with JS' quirks. But it's not such a big win that it's worth reformatting all our code (which I appreciate no one was proposing), and it might not even be a big enough with to be worth the attention it's gotten in this thread. Gavin On Thu, May 14, 2015 at 3:15 PM, Adam Roach <a...@mozilla.com> wrote: > On 5/14/15 16:33, Gijs Kruitbosch wrote: >> >> Can you give a concrete example where you had to change a contributor's >> patch in frontend gaia code to prefer === to prevent real bugs? > > > From what I've seen, it's typically a matter of making the results > unsurprising for subsequent code maintainers, because the rules of what gets > coerced to what are not intuitive. > > I'll crib from Crockford's examples (cf. "Appendix B: The Bad Parts" from > "JavaScript: The Good Parts"). How many of these can you correctly predict > the result of? > > 1. '' == '0' > 2. 0 == '' > 3. 0 == '0' > > 4. false == 'false' > 5. false == '0' > > 6. false == undefined > 7. false == null > 8. null == undefined > > 9. '\t\r\n' == 0 > > > I've posted the answers at https://pastebin.mozilla.org/8833537 > > If you had to think for more than a few moments to reach the right > conclusion about any of these -- or, heaven forbid, actually got one wrong > -- then I think you need to ultimately concede that the use of == is more > confusing than it needs to be. > > -- > Adam Roach > Principal Platform Engineer > a...@mozilla.com > +1 650 903 0800 x863 > > _______________________________________________ > dev-platform mailing list > dev-platform@lists.mozilla.org > https://lists.mozilla.org/listinfo/dev-platform _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform