2 ms·
Also, using 'class' as an IdentifierName is incorrectly explained in the answer for var a = {class: "Animal", name: 'Fido'}; a.class as this will correctl
by magicalist 13y ago
Also, using 'class' as an IdentifierName is incorrectly explained in the answer for
var a = {class: "Animal", name: 'Fido'};
a.class
as this will correctly return "Animal" in most browsers. It may be true that it's buggy in IE, but that's a bug, not part of the language. 'class' is a reserved word, but only as an Identifier, not an IdentifierName.
That might seem like a confusing splitting of hairs, but that's just due to the fact this is from a spec, not an explanation. In practice it basically means that you can't declare a variable with a reserved word name, but something like a property name (like a.class, or used when initializing a variable via an object literal) is fine using a reserved word.
In fact, the difference between an Identifier and an IdentifierName has allowed more than a few of the changes coming in ECMAScript 6 to be backwards compatible.
Even when not excusing browser bugs, there's a lot of sloppiness in this quiz.
- Zarel 13y ago`a.class` is explicitly legal in ES5, which is the spec that explicitly allows trailing commas in the `[,,,].join(", ")` question, so it's at least a bit confused about which version of JavaScript it's quizzing.