6 ms·
This question is wrong: What is the result of this expression? (or multiple ones) "1 2 3".replace(/d/g, parseInt) It says the correct answer is "
by Zarel 13y ago
This question is wrong:
What is the result of this expression? (or multiple ones)
"1 2 3".replace(/d/g, parseInt)
It says the correct answer is "1 NaN 3" but the real correct answer is "1 2 3". I assume it's a typo of:
"1 2 3".replace(/\d/g, parseInt)
In addition, for several questions, such as this:
var x = [].reverse; x();
Their 'official' answer is only true outside of strict mode. So to add to TheZenPsycho's comments, not only are these edge cases, many are edge cases that are known and that strict mode tries to solve.
I also object to []==[] being false as evidence that == is the spawn of Satan. == may be weird, but this is a case where === does the same thing. You just have to understand that [] and {} (and regex literals) construct new objects, and objects are compared by reference, not by value.
- chc 13y agoAnd one that has the right answer but explains it incorrectly: > What is the result of this expression? (or multiple ones) [1 < 2 < 3, 3 < 2 < 1] __[true, true]__ [true, false] error other > Implicit conversions at work. both true and false are greater than any number. True and false are greater than any number? What? This is not only not correct, it is contradicted by the answer. The real explanation is that 1 < 2 is true, which converts to 1, and thus less than 3; meanwhile, 3 < 2 is false, which converts to 0, and thus less than 1. This is actually the same result you would get in C.
- magicalist 13y agoFor the function f() {} var parent = Object.getPrototypeOf(f); typeof eval(parent.name) one, this is also wrong. I can't find anywhere in the spec that a name is required for Function.prototype[1], and 15.3.4.2 actually says that Function.prototype.toString() can return "An implementation-dependent representation of the function". Spidermonkey assigns it no name, so typeof eval(parent.name) just returns 'undefined', it doesn't throw an error. There's certainly no requirement that it be invocable by name, and, indeed, if v8 had left a function named 'Empty' in the global scope, that would have been bad. [1] http://es5.github.io/#x15.3.4 http://es5.github.io/#x15.3.4
- magicalist 13y agoAlso, 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.