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
?
char is a keyword that is used to declare a variable which store a character value from the range of +U0000 to U+FFFF.
char: The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).
Character ch = new Character('a'); The Java compiler will also create a Character object for you under some circumstances. For example, if you pass a primitive char into a method that expects an object, the compiler automatically converts the char to a Character for you.
There is no reserved keyword char in JavaScript, you must be confusing it with reserved keyword char of Java instead. ECMAScript 3 reserved all of the Java reserved words, and not every browser has yet implemented the ECMAScript 5 standard as JavaScript.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With