2

Most of the characters that are prohibited to be part of variable names in JS have special meaning:

  • &, *, %, ^, etc. are operators;
  • @ is used for declaring decorators;
  • branches (){}[] are a vital part of the language;
  • _ and $ that have no special meaning can be easily used as variable names.

What about the # char? Why is it special?

Kit Isaev
  • 680
  • 8
  • 19

2 Answers2

2

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

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
1

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.

eskimwier
  • 1,037
  • 13
  • 16