网上的一些javascript测试题,看你能对几道题?
http://dmitrysoshnikov.com/ecmascript/the-quiz/
1. What’s the result of:
typeof typeof(null)
A) “undefined”
B) SyntaxError
C)“string”
D) “object”
E) TypeError
2. Are the algorithms of the following checks completely equvalent?
typeof foo == 'undefined'
and
typeof foo === 'undefined'
A) Yes
B) No
3. What’s the result of:
100['toString']['length']
A)100
B) 3
C) 1
D) 8
E) 0
F) SyntaxError
4. What’s the result of:
var a = (1,5 - 1) * 2
A) 0.999999999
B) 1
C) 0.5
D) 8
E) -0.5
F) 4
5. What’s the result of:
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)() );
A) 20, 20, 20, 20
B) 20, 20, 10, 10
C) 20, 20, 20, 10
D) 20, 20, 10, 30
E) 20, 10, 10, 10
F) 20, 10, 30, SyntaxError
6. What’s the result of:
function f(x, y) { x = 10; console.log( arguments[0], arguments[1] ); } f();
A) 10, null
B) 10, undefined
C) undefined, undefined
D) 10, NaN
E) 10, 10
7. What’s the result of:
var b = 10, c = ( 20, function (x) { return x + 100}, function () { return arguments[0]} ); a = b + c ({x: 10}).x
A) 30, 10
B) 20
C) 10
D) 30, 110
E) NaN, 10
8. What’s the result of:
1..z
A) SyntaxError
B) New Range object (equivalent to new Range(1, ‘z’)) including all numbers and letters
C) undefined
D) Error of Range object (incompatible types for range: number and string)
E) ReferenceError “z” is not defined
9. What’s the result of:
({ x: 10, foo: function () { function bar() { console.log(x); console.log(y); console.log(this.x); } with (this) { var x = 20; var y = 30; bar.call(this); } } }).foo();
A) 20, 30, 20
B) 10, 30, 10
C) 20, undefined, 10
D) undefined, 30, 20
E) SyntaxError
F) 20, 30, 10
10. What’s the result of:
foreach (k in {a: 10, b: 20}) { // ... }
A) Always SyntaxError
B) ReferenceError or possibly no error
C) Always ReferenceError
D) Iteration over the object values
E) Iteration over the object keys
F) TypeError or possibly SyntaxError