I read some where else that following is illegal
var 3po = true;
but
var highNoon = false;
is legal.
Could someone explain what is all this means? Why the first statement is illegal while the second is legal?
I read some where else that following is illegal
var 3po = true;
but
var highNoon = false;
is legal.
Could someone explain what is all this means? Why the first statement is illegal while the second is legal?
An identifier cannot start with a number as the ECMAScript grammar explains:
Identifier ::
IdentifierName but not ReservedWord
IdentifierName ::
IdentifierStart
IdentifierName IdentifierPart
IdentifierStart ::
UnicodeLetter
$
_
\ UnicodeEscapeSequence
IdentifierPart ::
IdentifierStart
UnicodeCombiningMark
UnicodeDigit
UnicodeConnectorPunctuation
<ZWNJ>
<ZWJ>
I think you mean legal as in Syntax-wise?
The first example will give you a SyntaxError, the reason is that variables should not begin with a number.
You can find the answer in the EcmaScript documentation, page 15.
IdentifierName ::
IdentifierStart
IdentifierName IdentifierPart
IdentifierStart ::
UnicodeLetter
$
_
\ UnicodeEscapeSequence
So, the identifier could start from the letter, $, _ or unicode escape sequence, not the digit.
Is it possible that you meant "Why variables should not begin with a number?"
Just guesing...