I have seen test questions related to javascript posted by someone on Zhihu. I will share with you that although it happened a long time ago, these questions are quite classic, which makes people feel that javascript is really a painful language.
1.
The code copy is as follows:
(function () {
return typeof arguments;
})();
A. "object"
B. "array"
C. "arguments"
D. "undefined"
Answer: A
2.
The code copy is as follows:
var f = function g() {
return 23;
};
typeof g();
A. "number"
B. "undefined"
C. "function"
D. Eorror
Answer: D
3.
The code copy is as follows:
(function (x) {
delete x;
return x;
})(1);
A. 1
B. null
C. undefined
D. Error
Answer: A
4.
The code copy is as follows:
var y = 1,
x = y = typeof x;
x;
A. 1
B. "number"
C. undefined
D. "undefined"
Answer: D
5.
The code copy is as follows:
(function f(f) {
return typeof f();
})(function () {
return 1;
});
A. "number"
B. "undefined"
C. "function"
D. Error
Answer: A
6.
The code copy is as follows:
var foo = {
bar: function () {
return this.baz;
},
baz: 1
};
(function () {
return typeof arguments[0]();
})(foo.bar);
A. "undefined"
B. "object"
C. "number"
D. "function"
Answer: A
7.
The code copy is as follows:
var foo = {
bar: function () {
return this.baz;
},
baz: 1
};
typeof (f = foo.bar)();
A. "undefined"
B. "object"
C. "number"
D. "function"
Answer: A
8.
The code copy is as follows:
var f = (function f() {
return "1";
}, function g() {
return 2;
})();
typeof f;
A. "string"
B. "number"
C. "function"
D. "undefined"
Answer: B
9.
The code copy is as follows:
var x = 1;
if (function f() {}) {
x += typeof f;
}
x;
A. 1
B. "1function"
C. "1undefined"
D. NaN
Answer: C
10.
The code copy is as follows:
var x = [typeof x, typeof y][1];
typeof typeof x;
A. "number"
B. "string"
C. "undefined"
D. "object"
Answer: B
11.
The code copy is as follows:
(function (foo) {
return typeof foo.bar;
})({
foo: {
bar: 1
}
});
A. "undefined"
B. "object"
C. "number"
D. Error
Answer: A
12.
The code copy is as follows:
(function f() {
function f() {
return 1;
}
return f();
function f() {
return 2;
}
})();
A. 1
B, 2
C. Error (eg “Too much recursion”)
D. undefined
Answer: B
13.
The code copy is as follows:
function f() {
return f;
}
new f() instanceof f;
A. true
B, false
Answer: B
14.
The code copy is as follows:
with (function(x, undefined){}) length;
A. 1
B, 2
C. undefined
D. Error
Answer: B
15.
The code copy is as follows:
Which of the following statements will generate a running error: ()
A.var obj = ();
B.var obj = [];
C.var obj = {};
D.var obj = //;
Answer: A