user5171952
user5171952

Reputation:

Hashtag valid variable in javascript?

I have looked up valid variable names in javascript, and apparently the hashtag is not included in the list of characters. Can anyone tell me why this is?

Upvotes: 4

Views: 13371

Answers (3)

ha9u63a7
ha9u63a7

Reputation: 6824

With '#' being the prefix for private variables, there will also be restrictions with this in the future.

https://github.com/tc39/proposal-class-fields

Upvotes: 21

Chris Disley
Chris Disley

Reputation: 1355

If you mean #, it's invalid to use as part of a variable name because it's a punctuation mark. You wouldn't use a ',' either. It's not a mixed meaning thing like a '.' which is obviously because child properties/methods would be accessed using dot-notation, or a '>' which is obviously the operator for greater than, but it's just not something you should be using as a variable in any language (my opinion). Just makes things more readable to keep to Alpha/Alphanumeric and, at most, '_' or '-'.

Upvotes: 0

zon7
zon7

Reputation: 539

You can read about it here

A JavaScript identifier must start with a letter, underscore (_), or dollar sign ($); subsequent characters can also be digits (0-9). Because JavaScript is case sensitive, letters include the characters "A" through "Z" (uppercase) and the characters "a" through "z" (lowercase).

Upvotes: 3

Related Questions