Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the 'char' keyword used for?

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?

like image 207
MrBrody Avatar asked Apr 06 '12 16:04

MrBrody


People also ask

Is char a keyword?

char is a keyword that is used to declare a variable which store a character value from the range of +U0000 to U+FFFF.

What is the char data type in Java?

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).

How do you use char in Java?

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.

Is char a keyword in JavaScript?

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.


2 Answers

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.

like image 198
HoLyVieR Avatar answered Sep 27 '22 16:09

HoLyVieR


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.

like image 31
Sarfraz Avatar answered Sep 27 '22 17:09

Sarfraz