VK said:
Right. Must be changed to "converts to string on the background"
or "treats as string literal".
"Treats as string literal" would be false, as only string literal tokens
would be treated as string literals.
Typical of you to prefer to say something false.
but I'd like to keep the language as simplified as
technically possible.
It is technically possible for you to omit all words and code entirely,
and that is as simple as language gets.
I'm aware of CDATA and PCDATA usage.
But apparently unaware of their meaning or significance.
Unfortunately I'm still in search
for a right term for (from strictest to loosest):
1) string literals conforming to CSS class name rules.
2) string literals conforming to ID rules.
3) string literals conforming to JavaScript identifiers rules.
4) string literals conforming to NAME rules.
5) string literals conforming to no rules at all: @#*%$ Hhhh etc.
No string literal conforms to no rules at all. String literals conform
to string literal rules in whatever language they exist in.
The best term for 5) I've found so far is CDATA,
It would make as much sense to fabricate your own term by randomly
hitting keys on a keyboard and using whatever resulted. The term you
appear to be searching for is 'string literal', but string literals do
conform to well-defined rules or they are not going to be treated as
string literals.
however bad is it to apply it here.
Of course it is, it doesn't mean anything in the context of javascript.
If there is a better official term, I'll jump on it
gladly.
'string literal'.
I asked this question ("why 2 goes as the key, and 2cows doesn't?")
more than one year ago:
The only answer I got that time was "Everyone should know that"
Yes they should as the syntactically correct tokens in the context of a
property name in an object initialiser are Identifiers, string literals
and numeric literals and - 2cows - is none of those. Everyone should
know what qualifies as an Identifier, a numeric literal or a string
literal, that knowledge is so basic that you can hardly program in
javascript without knowing.
If fact - 2cows - will not be parsed as a single token, it is a numeric
literal token - 2 - followed by an Identifier token - cows -, and will
certainly result in a syntax error wherever it appears in javascript
source code.
from which I concluded that no one really knew,
Typical of you; you read one thing and then understand it to mean the
opposite. Given your tendency to make out that you actually know
something about javascript is it really surprising if you get short
answers when you ask absolutely basic questions with obvious answers?
so I had to investigate it myself.
And like most of your investigations the result was more false than not
knowing at all.
The posted explanation is totally correct:
It is incoherent gibberish. Correctness is not even an issue until the
text is coherent.
it is indeed not a problem with the key name by itself,
but with JavaScript parser looking at "2cows" as mistyped
2:cows
No, it is looking at - 2cows - and applying well-specified tokenising
rules that result in the two tokens - 2 - and - cows - and then seeing
that the - 2 - numeric literal token is not followed by the punctuator
token - : -, that is the only permissible token in that context within
an object initialiser, and so producing a syntax error. It is even an
informative syntax error. There is no need to ascribe any perception of
a typing error to the interpreter, the outcome is the certain
consequence of the application of the specified rules. It is pure
mechanism; blind deterministic mechanical logic.
...
Error: missing : after property id
Source Code:
var hash = {2cows:2};
...
Code that contains erroneous syntax produces a syntax error, and you
will look anywhere but the language's syntax rules for an explanation of
that.
var arr = new Array(1,2,3);
arr.foo = 'bar';
alert(arr);
Whatever significance you may see in that code is irrelevant unless you
are capable of expressing what it is. We can look up the definition of
the - toString - method of Arrays and see that the outcome here is in
accordance with the specification. Again, pure mechanical logic, not
self-awareness (or the lack thereof) on the part of the Array object. If
the Array's - toString - method was replaced with another many
alternative outcomes would be achievable, including one where the array
alerted - "bar, 1, 2, 3" -, which still implies nothing about Arrays
except that their - toString - methods are called when they are
type-converted into strings.
Richard.