var str1 = new RegExp("e");
document.write(str1.exec("hello"));
以上代码输出结果为( )
-
e
-
null
-
1
-
其他几项都不对
正确答案: A 你的答案: D (错误)
这就是一拿来匹配的正则表达式,然后返回匹配结果
以下代码执行后,result 的值是:
var result = Math.round(11.5) + Math.round(-11.5);
-
0
-
1
-
-1
正确答案: B 你的答案: A (错误)
Math.round(-11.5); // 结果是 -11
Math.round(-11.51); // 结果是 -12
Math.round(-11.49); // 结果是 -11
以下代码的输出结果是
var f = function g() {
return 23;
};
typeof g();
-
"number"
-
"undefined"
-
"function"
-
报错
在这里g不是一个函数,只是函数的一个内部属性,没有任何意义
以下代码执行后,array 的结果是?
let array = [, 1, , 2, , 3];
array = array.map((i) => ++i)
-
[,2,,3,,4]
-
[NaN,2,NaN,3,NaN,4]
-
[1,2,1,3,1,4]
-
[null,2,null,3,null,4]
正确答案: A 你的答案: B (错误)
ES5 map会跳过空位
ES6 map会将空位的值当作undefined (如果按现在的版本应该为B)
以下哪些表达式的值为0?
-
(()=>{}).length
-
1 & 2
-
+[]
-
[1,2,-3].reduce((a, b) => a - b, 0)
正确答案: A B C D 你的答案: A D (错误)
function a() { alert('ok') } console.log(a.length) //0
以上是针对A选项的解答
B选项中的&是位运算符AND,俩全是1才是1
C选项 []隐式转换成了0