小测验题目及答案

1 What is printed in the console?

1
2
3
4
5
var foo = function foo() {
console.log(foo === foo);
};
foo();
// true

2 What does the above

1
2
3
4
5
6
7
function aaa() {
return
{
test: 1
};
}
typeof aaa() // underfined

3 What is the result?

1
2
Number("1") - 1 == 0;
// true

4 3 What is the result?

1
2
(true + false) > 2 + true;
// false

5 What is?

1
2
3
4
5
6
7
8
function bar() {
return foo;
foo = 10;
function foo() {}
var foo = '11';
}
typeof bar()
// function

6 What is the result?

1
2
"1" - - "1";
// 2

7 What is the order of values?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
var x = 3;
var foo = {
x: 2,
baz: {
x: 1,
bar: function() {
return this.x;
}
}
}
var go = foo.baz.bar;
alert(go());
alert(foo.baz.bar());
// 3, 1

8 What is the result?

1
2
new String("This is a string") instanceof String;
// true

9 What is the result?

1
2
"This is a string" instanceof String;
// false

10 What is the result?

1
2
3
4
5
6
[] + [] + 'foo'.split('');
/*
[] + [] = ""
'foo'.split('') f,o,f
"f,o,o"
*/

11 What is the result?

1
2
3
new Array(5).toString();
//new Array(5) [,,,,]
// toString() ",,,,"

12 What is the result?

1
2
3
4
var myArr = ['foo', 'bar', 'baz'];
myArr.length = 0; // 清空myArr
myArr.push('bin');
console.log(myArr); // bin

13 What is the result?

1
2
3
String('Hello') === 'Hello'; // true
//String('Hello') 输出 Hello

14 What is printed on the console?

1
2
3
4
5
6
7
8
9
var x = 0;
function foo() {
x++;
this.x = x;
return foo;
}
var bar = new new foo;
console.log(bar.x);
// underfined

15 What is the result?

1
2
3
4
5
6
7
8
9
var bar = 1,
foo = {};
foo: {
bar: 2;
baz: ++bar;
};
foo.baz + foo.bar + bar;
// NAN

16 What is the result of console.log?

1
2
3
4
5
var myArr = ['foo', 'bar', 'baz'];
myArr[2];
console.log('2' in myArr);
'2' in 隐式转换 变成 number的 2
// true

17 What value is alerted?

1
2
3
4
5
6
7
var arr = [];
arr[0] = 'a';
arr[1] = 'b';
arr.foo = 'c';
alert(arr.length);
// arr = ['a', 'b', foo:'c']
// lngth = 2

18 What is the result?

1
2
3
4
5
6
10 > 9 > 8 === true;
// 10 > 9 = true
// true = 1 > 8 = false
//false === true
// false

19 What value is alerted?

1
2
3
4
5
6
function foo(a, b) {
arguments[1] = 2;
alert(b);
}
foo(1);
// underfined

20 What is the result?

1
2
3
NaN === NaN;
// NaN not a number
// false