Kit Isaev
Kit Isaev

Reputation: 700

Why # character is special in javascript?

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

Answers (2)

Bergi
Bergi

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

Upvotes: 2

eskimwier
eskimwier

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

Related Questions