当前位置:首页 > js复习
1、以下哪条语句会产生运行错误:(A) A.var obj = (); B.var obj = []; C.var obj = {}; D.var obj = //;
2、以下哪个单词不属于 javascript 保留字:(B) A.with B.parent C.class D.void
3、请选择结果为真的表达式:(C) A.null instanceof Object B.null === undefined C.null == undefined D.NaN == NaN
4. 关于正则表达式声明 6 位数字的邮编,以下代码正确的是( C ) A. var reg = /\\d6/; B. var reg = \\d{6}\\; C. var reg = /\\d{6}/;
D. var reg = new RegExp(\
5. 在表单(form1)中有一个文本框元素(fname), 用于输入电话号码, 格式如: 010-82668155,
要求前 3 位是 010,紧接一个“-” ,后面是 8 位数字。要求在提交表单时,根据上述条
件验证该文本框中输入内容的有效性,下列语句中, ( A )能正确实现以上功能
A. var str= form1.fname.value;
if(str.substr(0,4)!=\isNaN(parseFloat(str.substr(4)))) alert(\无效的电话号码!\B. var str= form1.fname.value;
if(str.substr(0,4)!=\isNaN(parseFloat(str.substr(4)))) alert(\无效的电话号码!\C. var str= form1.fname.value;
if(str.substr(0,3)!=\isNaN(parseFloat(str.substr(3)))) alert(\无效的电话号码!\D. var str= form1.fname.value;
if(str.substr(0,4)!=\!isNaN(parseFloat(str.substr(4)))) alert(\无效的电话号码!\
1. What is the result of this expression? (or multiple ones) [\ A:[\B:[1, 2, 3] C:[0, 1, 2] D:other
解答:这里考的是map、parseInt的用法。map会传递三个参数给其作为参数的函数,为(element, index, array),分别为当前的元素、当前元素在数组中的位置、整个数组:
> [\ [\[\[\
而parseInt只接收两个参数,为(element, radix),element代表需要被转换为int的字符串,radix代表当前字符串里数字的进制数 所以相当于说,结果数组的元素实际分别为为: parseInt(\parseInt(\parseInt(\
parseInt(\的值为1,MDN上可以看到parseInt函数的radix为0时的行为
If radix is undefined or 0 (or absent), JavaScript assumes the following:
If the input string begins with \and the remainder of the string is parsed.
If the input string begins with \(decimal). Exactly which radix is chosen is
implementation-dependent. ECMAScript 5 specifies that 10 (decimal) is used, but not all browsers support this yet. For this reason always specify a radix when using parseInt.
If the input string begins with any other value, the radix is 10 (decimal).
所以这里radix值实际为10,所以结果为1
而parseInt(\和parseInt(\则确实无法解析,会生成NaN 所以答案为[1,NaN,NaN],为D
2. What is the result of this expression? (or multiple ones) [typeof null, null instanceof Object] A: [\B: [null, false] C: [\D: other
考察typeof运算符和instanceof运算符,上MDN上看一下typeof运算符,一些基础类型的结果为: Undefined \Null \
Boolean \Number \String \
Any other object \Array \
自从javascript创造出来,typeof null的值就是object了 而null instanceof 任何类型 都是false 所以答案为[\选A
3. What is the result of this expression? (or multiple ones) [ [3,2,1].reduce(Math.pow), [].reduce(Math.pow)] ] A: an error B: [9, 0] C: [9, NaN]
D: [9, undefined]
这题考的Math.pow和Array.prototype.reduce
Math.pow(base, exponent)接受两个参数:基数、需要计算的次方 reduce传递给其作为参数的函数几个值: * previousValue:上一次计算的结果 * currentValue:当前元素的值
* index: 当前元素在数组中的位置 * array:整个数组
reduce本身接受两个参数,callback和initialValue,分别是reduce的回调函数和计算初始值--也就是第一次reduce的callback被调用时的previousValue的值,默认为0
共分享92篇相关文档