javascript不可能全会的30道题

1,以下表达式的运行结果是:
  1. ["1","2","3"].map(parseInt)
复制代码

A.["1","2","3"]
B.[1,2,3]
C.[0,1,2]
D.其他

答:D 

['1' , '2', '3',].map(parseInt)->[ parseInt(1,0),parseInt(2,1),parseInt(3,2)]->[1,NAN,NAN]

解析:map()函数对数组中的每个值 调用map()中的回调函数,回调函数有三个参数,function(value,index,array)

所以该题目不同于:
function testFuc(a){
        return parseInt(a);
}
console.info(["1","2","3"].map(testFuc));

map中回调函数的语法如下所示:function callbackfn(value, index, array1),可使用最多三个参数来声明回调函数。第一参数value,数组元素的值;第二个参数index,数组元素的数组所以;array1,包含该元素的数组对象。
因此,题目等同于[parseInt(1,0),parseInt(2,1),parseInt(3,2)]

对于函数来说等同于function testFuc(a,x){

        return parseInt(a,x);
}
console.info(["1","2","3"].map(testFuc));

对于parseInt(string,radix)来说 

radix可选。表示要解析的数字的基数。该值介于 2 ~ 36 之间。

如果省略该参数或其值为 0,则数字将以 10 为基础来解析。如果它以 “0x” 或 “0X” 开头,将以 16 为基数。

如果该参数小于 2 或者大于 36,则 parseInt() 将返回 NaN。

 说明:

(1) 当参数 radix 的值为 0,或没有设置该参数时,parseInt() 会根据 string 来判断数字的基数。

举例,如果 string 以 "0x" 开头,parseInt() 会把 string 的其余部分解析为十六进制的整数。如果 string 以 0 开头,那么 ECMAScript v3 允许 parseInt() 的一个实现把其后的字符解析为八进制或十六进制的数字。如果 string 以 1 ~ 9 的数字开头,parseInt() 将把它解析为十进制的整数。

parseInt(3,2),3不能是2进制,所以 返回NAN   parseInt(2,1) 返回NAN  string 必须是符合后面相应基数的数字的字符串

举个好吃的栗子:我们将使用 parseInt() 来解析不同的字符串:

parseInt("10");			//返回 10
parseInt("19",10);		//返回 19 (10+9)
parseInt("11",2);		//返回 3 (2+1)
parseInt("17",8);		//返回 15 (8+7)
parseInt("1f",16);		//返回 31 (16+15)
parseInt("010");		//未定:返回 10 或 8


2,以下表达式的运行结果是:

  1. [typeof null, null instanceof Object]
复制代码

A.["object",false]
B.[null,false]
C.["object",true]

D.其他

2,A
typeof用以获取一个变量或者表达式的类型,typeof一般只能返回如下几个结果:
number,boolean,string,function(函数),object(NULL,数组,对象),undefined。
instanceof 表示某个变量是否是某个对象的实例,null是个特殊的Object类型的值 ,表示空引用的意思 。但null返回object这个其实是最初JavaScript的实现的一个错误, 
然后被ECMAScript沿用了,成为了现在的标准,不过我们把null可以理解为尚未存在的对象的占位符,这样就不矛盾了 ,虽然这是一种“辩解”。
对于我们开发人员 还是要警惕这种“语言特性”。最终返回:["object", false]

3,以下表达式的运行结果是:

  1. [[3,2,1].reduce(Math.pow),[].reduce(Math.pow)]
复制代码

A.报错
B.[9,0]
C.[9,NaN]
D.[9,undefined]

4,以下表达式的运行结果是:
  1. var val = 'value';
  2. console.info('Value id '+(val === 'value')?'Something':'Nothing');
复制代码

A.Something
B.Nothing
C.NaN
D.其他

5,以下表达式的运行结果是:
  1. var name = 'World';
  2. (function(){
  3. if(typeof name === 'undefined'){
  4. var name = "Jack";
  5. console.info('Goodbye '+ name);
  6. }else{
  7. console.info('Hello ' + name);
  8. }
  9. })();
复制代码

A.Goodbye Jack
B.Hello Jack
C.Goodbye undefined
D.Hello undefined

6,以下表达式的运行结果是:
var START = END -100;
var count = 0;
for(var i = START ; i <= END ;i++){
count ++;
}
console.info(count);
A.0
B.100
C.101
D.其他

7,以下表达式的运行结果是:
var arr = [0,1,2];
arr[10] = 10;
arr.filter(function(x){return x === undefined});
A.[undefined x 7]
B.[0,1,2,10]
C.[]
D.[undefined]

8,以下表达式的运行结果是:
var two = 0.2;
var one = 0.1;
var eight = 0.8;
var six = 0.6;
[two -one == one,eight- six == two];
A.[true,true]
B.[false,false]
C.[true,false]
D.其他

9,以下表达式的运行结果是:
  1. function showCase(value){
  2. switch(value){
  3. case 'A':
  4. console.info('Case A');
  5. break;
  6. case 'B':
  7. console.info('Case B');
  8. break;
  9. case undefined :
  10. console.info('undefined');
  11. break;
  12. default:
  13. console.info('Do not know!');
  14. }
  15. }
  16. showCase(new String('A'));
复制代码

复制代码

A.Case A
B.Case B
C.Do not know
D.undefined

10,以下表达式的运行结果是:
  1. function showCase(value){
  2. switch(value){
  3. case 'A':
  4. console.info('Case A');
  5. break;
  6. case 'B':
  7. console.info('Case B');
  8. break;
  9. case undefined :
  10. console.info('undefined');
  11. break;
  12. default:
  13. console.info('Do not know!');
  14. }
  15. }
  16. showCase(String('A'));
复制代码

复制代码

A.Case A
B.Case B
C.Do not know
D.undefined

11,以下表达式的运行结果是:
  1. function isOdd(num){
  2. return num % 2 == 1;
  3. }
  4. function isEven(num){
  5. return num % 2 == 0;
  6. }
  7. function isSane(num){
  8. return isEven(num)||isOdd(num);
  9. }
  10. var values = [7,4,'13',-9,Infinity];
  11. values.map(isSane);
复制代码

复制代码

A.[true, true, true, true, true]
B.[true, true, true, true, false]
C.[true, true, true, false, false]
D.[true, true, false, false, false]

12,以下表达式的运行结果是:
[parseInt(3,8),parseInt(3,2),parseInt(3,0)]
A.[3,3,3]
B.[3,3,NaN]
C.[3,NaN,NaN]
D.其他

13,以下表达式的运行结果是:
 Array.isArray(Array.prototype)
A.true
B.false
C.报错
D.其他

14,以下表达式的运行结果是:
var a = [0];
if([0]){
console.info(a == true);
}else{
console.info("else");
}
复制代码

A.true
B.false
C."else"
D.其他

15,以下表达式的运行结果是:
[]==[]
A.true
B.false
C.报错
D.其他

16,以下表达式的运行结果是:
[('5'+3),('5'-3)]
A.["53",2]
B.[8,2]
C.报错
D.其他

17,以下表达式的运行结果是:
1+-+++-+1
A.true
B.false
C.报错
D.其他

18,以下表达式的运行结果是:
var arr = Array(3);
arr[0] = 2
arr.map(function(elem){return '1';});
A.[2,1,1]
B.["1","1","1"]
C.[2,"1","1"]
D.其他

19,以下表达式的运行结果是:
function sidEffecting(arr){
arr[0] = arr[2];
}
function bar(a,b,c){
c = 10;
sidEffecting(arguments);
return a+b+c;
}
bar(1,1,1);
复制代码

A.3
B.12
C.报错
D.其他

20,以下表达式的运行结果是:
var a = 111111111111111110000;
b = 1111;
console.info(a+b);
A.111111111111111111111
B.111111111111111110000
C.NaN
D.Infinity

21,以下表达式的运行结果是:
ar x = [].reverse;
x();
A.[]
B.undefined
C.报错
D.window

22,以下表达式的运行结果是:
Number.MIN_VALUE>0
A.true
B.false
C.报错
D.其他

23,以下表达式的运行结果是:
[1<2<3,3<2<1]
A.[true,true]
B.[true,false]
C.报错
D.其他

24,以下表达式的运行结果是:
2 == [[[2]]]
A.true
B.false
C.undefined
D.其他

25,以下表达式的运行结果是:
[3.toString(),3..toString(),3...toString()]
A.["3",error,error]
B.["3","3.0",error]
C.[error,"3",error]
D.其他

26,以下表达式的运行结果是:
(function(){
var x1 =y1 =1;
})();
console.info(y1);
console.info(x1);
A.1,1
B.error,error
C.1,error
D.其他

27,列举IE和FF脚本兼容性的问题

28,以下函数有什么问题?如何改进?
  1. function initButtons(){
  2. var body = document.body,button,i;
  3. for(i =0;i<5;i++){
  4. button = document.createElement("button");
  5. button.innerHTML = "Button" + i;
  6. button.addEventListener("click",function(e){
  7. alert(i);
  8. },false);
  9. body.appendChild(button);
  10. }
  11. }
  12. initButtons();
复制代码

复制代码


29,写一段代码,判断一个字符串中出现次数最多的字符,并统计出现的次数。

30,请问一下两段代码有什么不同?
  1. setTimeout(function(){
  2. /*代码块*/
  3. setTimeout(arguments.callee,10);
  4. },10);
  5. setInterval(function(){
  6. /*代码块*/
  7. },10);
复制代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值