admin管理员组文章数量:1328637
I'm not talking about in the URL. I know what that does. I'm talking about how it's used in actual code.
After trying to assign it as a variable, I realized that it's reserved, but I don't know what for.
I'm not talking about in the URL. I know what that does. I'm talking about how it's used in actual code.
After trying to assign it as a variable, I realized that it's reserved, but I don't know what for.
Share Improve this question edited Jun 1, 2024 at 13:17 dumbass 27.3k4 gold badges37 silver badges73 bronze badges asked Mar 8, 2011 at 15:38 McKaylaMcKayla 6,9595 gold badges39 silver badges49 bronze badges 2-
So you're trying to do
var # = "foo"
and # is reserved? – Surreal Dreams Commented Mar 8, 2011 at 15:43 - 1 Could you specify what you mean? – Johannes Fahrenkrug Commented Mar 8, 2011 at 15:50
5 Answers
Reset to default 2An ongoing proposal (currently in stage 4) utilizes hashtags to mark fields as private. It is part of the ES2022 standard.
Example:
class Foo {
x = 1; // public field
#y = 2; // private field
add() {
return this.x + this.#y;
}
}
Javascript, or more precisely ECMAscript, is an evolving language. Some symbols and keywords (such as "class") have been reserved for future versions, even though they may not have any meaning at the moment.
I dont think, that this sign is somehow reserved fot another functionality. I found that rule here:
You must not use any punctuation marks of any kind in a JavaScript variable name, other than the underscore; for example... some:thing or big# or do'to would all be illegal.
This ist just, that javascript does not accept punctation signs in variable names ant due to this not parsing variables named like this as variables.
See here: What characters are valid for JavaScript variable names?
In JavaScript variable names, no punctuation marks are permitted except for the underscore (_) and dollar sign ($). You can't start a variable name with a number, but otherwise all letters and numbers are permitted in a variable name.
So you can't have a variable name with #
in it, no less a variable named #
. It has no special meaning, it's just not permitted just as variable can't be named ~
.
本文标签: What is the hash character () used for in JavaScriptStack Overflow
版权声明:本文标题:What is the hash character (#) used for in JavaScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742225948a2436319.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论