946 words

Remember that crazy Javascript quiz from 6 years ago? Craving to solve another set of mind-bending snippets no sensible developer would ever use in their code? Looking for a new installment of the most ridiculous Javascript interview questions?

Look no further! The "ECMAScript Two Thousand Fifteen" installment of good old Javascript Quiz is finally here.

The rules are as usual:

Assuming ECMA-262 6th Edition

Implementation quirks do not count (assuming standard behavior only)

Every snippet is run as a global code (not in eval, function, or module contexts)

There are no other variables declared (and host environment is not extended with anything beyond what's defined in a spec)

Answer should correspond to exact return value of entire expression/statement (or last line)

"Error" in answer indicates that overall snippet results in a compile or runtime error

Cheating with Babel doesn't count (and there could even be bugs!)

The quiz goes over such ES6 topics as: classes, computed properties, spread operator, generators, template strings, and shorthand properties. It's relatively easy, but still tricky. It tries to cover various ES6 features — a little bit of this, a little bit of that — but it's certainly still only a tiny subset.

If you can think of other silly riddle ideas to break one's head against, please post them in the comments. For a slightly harder version, feel free to explore some of the tests in our compat table or perhaps something from TC39 official test suite.

Ready? Here we go.

[2, 1, 1]

[2, undefined, 1]

[2, 1, 2]

[2, undefined, 2] ['inner', 'outer']

['outer', 'outer']

[undefined, undefined]

Error undefined

1

{ x: 1 }

Error ["function", "undefined"]

["function", "function"]

["undefined", "undefined"]

Error "function"

"object"

"undefined"

Error "function"

"object"

"undefined"

Error 1

3

6

Error "function"

"generator"

"object"

Error "function"

"undefined"

"object"

Error "function"

"undefined"

"object"

Error 1

3

[1,2,3]

Error [2, { x: 1 }, 2, 2, 2, { y }]

[{ x: 1 }, 2, { y }]

[1, undefined, 2, undefined, 2, undefined]

Error "function"

"undefined"

"object"

Error

Let's see the score!

Here be quiz result

I hope you enjoyed it. I'll try to write up an explanation for these in the near future.