There are two lessons to be learned from this:

  1. 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.
  2. Consider putting your variable in the right hand of the assignment.1 There’s a reason most textbooks show if statements 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.

  1. This advice isn’t popular because it hurts readability and admits of a weakness on the part of the developer. If you’re using ESLint then you can achieve the same result with the no-cond-assign rule. ↩︎