Reputation: 700
Most of the characters that are prohibited to be part of variable names in JS have special meaning:
What about the # char? Why is it special?
Upvotes: 2
Views: 63
Reputation: 664620
There is nothing special about #
. It's just one of the many characters that are no valid Unicode Identifier Start or Identifier Continue. A better question might have been what makes $
and _
special so that they became valid identifier parts?
What might make it special is that it's one of the few printable ASCII characters that are invalid as identifier names but also were not used as punctuators anywhere else in EcmaScript 1. There are
`
, which is used as the delimiter for template literals since ES6@
, which is proposed to be used for decorator syntax#
, which is proposed to be used for private field syntaxUpvotes: 2
Reputation: 1107
My guess is that languages haven't generally allowed the pound #
character in variable names, and JavaScript followed suit.
Additionally, since it is the character to start a comment in quite a few languages, it could be seen as a pointless and potentially confusing thing to add.
Upvotes: 1