After reading js quiz from kangax, Dmitry Soshnikov, I think it is better if collecting some great js quizzes. There are also some quizzes created myself, I realize when program.

Few notes about code

  • Assuming ECMAScript 5th edition
  • Every snippet is run as a global code
  • There are no other variables declared


1.

(function(){
  return typeof arguments;
})();

2.

var f = function g(){ return 23; };
typeof g();

3.

(function(x){
  delete x;
  return x;
})(1);

4. What's the value of x?

var y = 1, x = y = typeof x;

5.

(function f(f){
  return typeof f();
})(function(){ return 1; });

6.

var f = (function f(){ return "1"; }, function g(){ return 2; })();
typeof f;

7. What's the value of x?

var x = 1;
if (function f(){}) {
  x += typeof f;
}

8.

var x = [typeof x, typeof y][1];
typeof typeof x;

9.

(function f(){
  function f(){ return 1; }
  return f();
  function f(){ return 2; }
})();

10.

function f(){ return f; }
new f() instanceof f;

11.

function foo() {
  return this;
}

alert(foo === foo.prototype.constructor); // true
alert(foo() === foo.prototype.constructor()); // ?

12. What will alert display?

a = {
  n: function(){alert(this.b)},
  b: 1
};
(a.m = a.n)() // ?

13.

parseInt("12.5") === ~~"12.5";

14.

100['toString']['length']

15. What's the value of a?

if (!("a" in window)) {
  var a = 1;
}

16. What's the value of a?

function a(x) {
  return x * 2;
}
var a;

17.

function a() {
  console.log(this);
}
a.call(null);

18.

typeof typeof(null)

19. Are they completely equvalent?

typeof foo == 'undefined' vs typeof foo === 'undefined'

20. What's the value of a?

var a = (1,5 - 1) * 2

21. What's the result of below expression?

var x = 10;
var foo = {
  x: 20,
  bar: function () {
    var x = 30;
    return this.x;
  }
};

console.log(
  foo.bar(),
  (foo.bar)(),
  (foo.bar = foo.bar)(),
  (foo.bar, foo.bar)()
);

22.

function f(x, y) {
  x = 10;
  console.log(arguments[0], arguments[1]);
}

f();

23.

function b(x, y, a) {
  arguments[2] = 10;
  alert(a);
}
b(1, 2, 3);

24.

var
b = 10,
c = (
  20,
  function (x) { return x + 100},
  function () { return arguments[0]}
);

a = b + c
({x: 10}).x

25.

(function () {
    console.log("bar");
})

(function () {
    console.log("foo");
}());

26.

if (true) {
  function foo() {
    return 'first';
  }
}
else {
  function foo() {
    return 'second';
  }
}
foo();

27

[] == ![]