There are two lessons to be learned from this:
- Always assume that your error messages will be seen by real users at some point, and write them accordingly. Think twice before being snarky, unless snarky is your brand.
- Consider putting your variable in the right hand of the assignment.1 There’s a reason most textbooks show
ifstatements this way, with the literal comparison on the left hand side and the variable on the right hand. If you do that, this sort of bug is impossible. If you use a single
=with that method, instead of shipping a subtle(ish) bug, you’ll get this helpful error:
Uncaught ReferenceError: Invalid left-hand side in assignment.
Tuesday, January 2, 2018