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

Reply via email to