Why does 2+ 40 equal 42?

I was baffled when a colleague showed me this line of JavaScript alerting 42.

alert(2+ 40);

It quickly turns out that what looks like a minus sign is actually an arcane Unicode character with clearly different semantics.

This left me wondering why that character doesn’t produce a syntax error when the expression is parsed. I’d also like to know if there are more characters behaving like this.

6 Answers
6

Leave a Comment