问题
What is the char
reserved keyword used for in JavaScript (as type declaration is not necessary), and especially, what is the correct syntax to use it (could someone give me a proper full example)?
Because writing char c;
throws an interpretation error saying missing ; before statement
, just before the c
?
回答1:
There are a lot of reserved keyword in JavaScript that are reserved for "future" use. They don't necessarily have a current use and a description.
MDN does list some of them that have this special "future use" status here : https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words (thanks to DCoder) and you can also read from that article :
The following are reserved as future keywords by the ECMAScript specification. They have no special functionality at present, but they might at some future time, so they cannot be used as identifiers. These keywords may not be used in either strict or non-strict mode.
To expand a little further as to why it's consider a reserved keyword in some places and in some places it's not. The ECMAScript v3 specification did include char
as a reserved keyword, but the ECMAScript v5 specification (which is starting to be the most common one) does not include it.
回答2:
Update:
Also as @HoLyVieR pointed out and shown in comments below, char
keyword is reserved for future use. See this link for more information (Thanks to @djmadscribbler) .
There is no reserved keyword char in JavaScript, you must be confusing it with reserved keyword char of Java instead.
回答3:
According to the ECMAscript documentation ( http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf section 7.6.1 ) char isn't a reserved word at all.
I'm guessing if you're seeing that as a reserved word somewhere then it's a specific implementation.
http://jsfiddle.net/BCruP/
Edit: Above reference was EMCAscript 5.
EMCAScript 3 ( http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf ) documentation lists char as a future reserved word, however, EMCAScript 5 seems to have dropped that off the list.
来源:https://stackoverflow.com/questions/10046439/what-is-the-char-keyword-used-for