Skip to content

Instantly share code, notes, and snippets.

@teramako
Last active August 20, 2018 01:46
Show Gist options
  • Save teramako/858c448cb76cb8d309b0 to your computer and use it in GitHub Desktop.
Save teramako/858c448cb76cb8d309b0 to your computer and use it in GitHub Desktop.

ECMAScript6th Quiz

Q.1

let func = function() {};
func.name
  1. ""
  2. "func"
  3. "anonymous"
  4. undefined

Q.2

var DOLPHIN = "\ud83d\udc2c";
DOLPHIN.length + [...DOLPHIN].length
  1. 2
  2. 3
  3. 4

Q.3

var sym1 = Symbol(),
    sym2 = Symbol();
var o1 = {},
    o2 = {};
Object.defineProperties(o2, {
    [sym1]: { value: "Sym 1", enumerable: true },
    [sym2]: { value: "Sym 2"}
});
Object.assign(o1, o2);
Object.getOwnPropertySymbols(o1).length + Object.getOwnPropertySymbols(o2).length;
  1. 1
  2. 2
  3. 3
  4. 4

Q.4

var obj1 = { ["__proto__"]: "FOO" };
var obj2 = { __proto__: "FOO" };
var obj3 = { "__proto__": "FOO" };
[
  obj1.hasOwnProperty("__proto__"), 
  obj2.hasOwnProperty("__proto__"), 
  obj3.hasOwnProperty("__proto__")
]
  1. [true, true, true]
  2. [true, false, false]
  3. [true, false, true]
  4. [false, false, false]
  5. [false, true, true]
  6. thrown TypeError

Q.5

function foo (a, b) {
  "use strict";
  var arrow = () => { return arguments[0]; };
  return arrow(b);
};
foo("A", "B")
  1. "A"
  2. "B"
  3. thrown TypeError

Q.6

var f = () => { foo: "BAR" };
typeof f();
  1. "string"
  2. "object"
  3. "undefined"

Q.7

[
  String.raw`Line\nTerminator` == "Line\\nTerminator",
  `\u3042` == "\u3042",
  String.raw`\u3042` == "\u3042",
]
  1. [true, true, true]
  2. [false, true, true]
  3. [true, true, false]
  4. [false, true, false]

Q.8

function foo () {
  return "out";
}
var obj = {
  foo(n) {
    if (n) { return "in"; }
    return foo(1) + "side";
  }
};
obj.foo();
  1. "outside"
  2. "inside"
  3. thrown InternalError: too much recursion

Q.9

var f = () => { foo: function(){ return "FOO" } };
typeof f();
  1. "object"
  2. "function"
  3. "undefined"
  4. thrown SyntaxError

Q.10

"use strict";
var f = () => { foo: function foo(){ return "FOO" } };
typeof f();
  1. "object"
  2. "function"
  3. "undefined"
  4. thrown SyntaxError

Q.11

var obj = {
  init() {
    this.name = "obj";
  },
  Foo() {
    this.init();
  }
};
obj.Foo.prototype = {
  init() {
    this.name = "Foo";
  },
};
var foo = new obj.Foo();
[
  obj.name, foo.name
];
  1. ["obj", undefined]
  2. ["Foo", undefined]
  3. [undefined, "Foo"]
  4. thrown SyntaxError
  5. thrown TypeError

Q.12

Thanks: https://twitter.com/ziyunfei/status/571704467130736640

(function(arg1, ...rest) {
  arg1 = 10;
  return arguments[0];
}(1,2,3));
  1. 1
  2. 10
  3. thrown SyntaxError
  4. thrown TypeError

Q.13

Thanks: https://twitter.com/ziyunfei/status/571828310759510016

console.log([
 1 in Array(3),
 1 in new Array(3),
 1 in Array.from(Array(3)),
 1 in Array(3).fill(),
 1 in [...[,,,]]
]);
  1. [false, true, true, false, true]
  2. [false, false, false, false, false]
  3. [false, false, true, true, true]

Q.14

Thanks: https://twitter.com/ziyunfei/status/571831478323056640

var result = [];

function findFirstUndefined(value, index) {
  if (value === undefined) {
    result.push(index);
    return true;
  }
}

[1, , 3].some(findFirstUndefined);
[1, , 3].find(findFirstUndefined);

console.log(result);
  1. [1, 1]
  2. []
  3. [1]
  4. thrown TypeError

Q.15

Thanks: https://twitter.com/ziyunfei/status/572262011003789312

function getPrototypeChainOf(obj) {
    var prototypeChain = [];
    while (obj = Object.getPrototypeOf(obj)) {
        prototypeChain.push(obj);
    }
    return prototypeChain;
}
var g = function *(){};
getPrototypeChainOf(g()).length;
  1. 2
  2. 3
  3. 4
  4. 5

Q.16

var list = ["1", NaN, 3, "a"];
var sum = (c,p)=> c+p;
[
 list.map(Number.isNaN).reduce(sum),
 list.map(isNaN).reduce(sum)
];
  1. [1, 1]
  2. [1, 2]
  3. [2, 1]
  4. [2, 2]

Q.17

var obj = {
  length: 3,
  *[Symbol.iterator](){
    yield "A";
    yield "B";
  }
};
Array.from(obj).length;
  1. 2
  2. 3
  3. thrown TypeError

Answer

ES6_Quiz_Answer

@hebuliang
Copy link

I tried Q.11 in Traceur, but i got [ undefined, 'Foo' ], seems different with the Answer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment