Destructuring 使用默认测验
单选题 中等
题目
什么是 值的 `port` 之后 `const { port = 3000 } = { host: 'localhost' }`?
提示
默认值 in destructuring 是 used 当属性是 undefined.
解释
当 destructuring, 默认值 是 used 如果属性是 undefined or absent. 对象 { host: 'localhost' } 有否 port 属性, 所以 port takes 默认值 3000. 如果对象有 port: undefined, 默认会 也 apply. 如果它 有 port: 8080, 默认会 不 apply.
相关资源
相关课程
- JavaScript 对象
学习关于 destructuring defaults.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。