1const createMember = ({ email, address = {}}) => { 2 const validEmail = /.+\@.+\..+/.test(email) 3 if (!validEmail) throw new Error("Valid email pls") 4 5 return { 6 email, 7 address: address ? address : null 8 } 9} 10 11const member = createMember({ email: "my@email.com" }) 12console.log(member)
本题为“单选题”
参考答案:
正确选项:C:{ email: "my@email.com", address: {} }
address
的默认值是一个空对象 {}
。当我们设置 member
变量为 createMember
函数返回的对象,我们没有为address参数传值,意味着address的值为默认的空对象 {}
。一个空对象是一个truthy值,意味着 address ? address : null
条件会返回 true
。address的值为空对象 {}
。
最近更新时间:2021-07-03