前端笔试选择题——day4
输出什么
let newList = [1,2,3].push(4)
console.log(newList.push(5))
A. [1,2,3,4,5]
B. [1,2,3,5]
C. [1,2,3,4]
D. Error
解析:
push
方法会修改原数组,在数组的最后添加一个元素
但是push
方法的返回值是数组的长度,而不是数组本身;所以newList
为4
,数字4
没有psuh
方法自然会报错
输出什么
// counter.js
let counter = 10;
export default counter
import myCounter from "./counter"
myCounter += 1;
console.log(myCounter);
A. 10
B. 11
C. Error
D. NaN
解析:
引入的模块是只读的,你不能修改引入的模块;只有导出它们的模块才能修改其值
当我们这样做会发生什么
function bark(){
console.log('Woof!')
}
bark.animal = 'dog'
A. Nothing, this is totally fine
B. SyntaxError. You cannot add properties to a function this way
C. undefined
D. ReferenceError
在JavaScript中,除原始类型之外的所有东西都是对象
函数是一种特殊类型的对象,对象可以有自己的属性且可调用
输出什么
const spookyItems = ["?","?","?"];
({item:spookyItems[3]} = {item:"?"});
console.log(spookyItems);
A. [“?”,“?”,“?”]
B. [“?”,“?”,“?”,“?”]
C. [“?”,“?”,“?”,{item:“?”}]
D. [“?”,“?”,“?”,“[object Object}”]
解析:
通过解构对象,我们可以从右边对象中拆出值,并且将拆除的值分配给左边对象同名的属性
相当于spookyItems [3] = "?"
输出什么
const info = {
[Symbol('a')]:'b'
}
console.log(info)
console.log(Object.keys(info))
A. {Symbol(‘a’):‘b’} and [“Symbol(‘a’)”]
B. {} and []
C. {a:“b”} and [“a”]
D. {Symbol(‘a’):‘b’} and []
解析:
打印整个对象的时候,所有属性都是可见的,甚至是不可枚举属性
Symbol
类型是不可枚举的。Object.key
方法返回对象上所有可枚举的属性的数组,所以返回一个空数组
输出什么
[1,2,3].map(num => {
if (typeof num === 'number') return;
return num * 2;
})
A. []
B. [null,null,null]
C. [undefined,undefined,undefined]
D.[3 * empty]
解析:
当函数没有返回任何值时,及默认返回undefined