Every non-trivial language has "gotchas". Here's one. Consider the following JScript, which creates an object and sets some fields to zero:
var x =
{
0 : 0,
123 : 0,
1.23 : 0,
blah : 0,
"dude!" : 0,
"-1.23" : 0
};
A little weird, but it works just fine. How about this?
var x = { -1 : 0 };
That fails with the message "expected identifier, string or number".
Pop quiz: what the heck is going on here? Surely that is an "identifier, string or number", no?
Comment Notification
If you would like to receive an email when updates are made to this post, please register here
Subscribe to this post's comments using
About Eric Lippert
Eric Lippert is a senior developer on the Microsoft C# compiler team. Before that he worked on the framework of Visual Studio Tools For Office. Before that, he worked on the compilers, runtimes and tools for VBScript, JScript, Windows Script Host and other Microsoft Scripting technologies. He lives in Seattle and spends his free time editing books about programming languages, playing the piano, and trying to keep his tiny sailboat upright in Puget Sound.