Key to ‘JavaScript Puzzlers'(3)
4.What is the result of this expression? (or multiple ones)
1 | var END = Math.pow(2, 53); |
A 0
B 100
C 101
D other
Correct answer is D.253 is the largest number in javascript,so that i never become lager than START.This code will cause infinite loop.
5.What is the result of this expression? (or multiple ones)
1 | var ary = [0,1,2]; |
A [undefined x 7]
B [0,1,2,10]
C []
D [undefined]
C is correct answer.The ary looks like [0,1,2,undefined x 7,10] , but in fact array.prototype.filter() ignore undefined element.So it returned [] > See more information about array.prototype.filter()
6.What is the result of this expression? (or multiple ones)
1 | var two = 0.2 |
A [true,true]
B [false,false]
C [true,false]
D other
Is C.
Javascript hasn't ability of precise calculation,so that float number will be calculated in a imprecise mode.
> 0.8-0.6 = 0.20000000000000007
Specially, 0.2-0.1 = 0.1
7.What is the result of this expression? (or multiple ones)
1 | function showCase2(value) { |
A Case A
B Case B
C Do not know!
D undefined
swith() method uses '===' to judge condition,new String(A) construct a new string object,
new String('a') == 'a' but new String('a') !== 'a'.
So this question's answer is C
let a = new String("b")
typeof a === 'object'
8.What is the result of this expression? (or multiple ones)
1 | function showCase2(value) { |
A Case A
B Case B
C Do not know!
D undefined
Correct is A.
String('A') === 'A'
let a = String('b')
typeof a === 'string'