相关疑难解决方法(0)

使用默认参数解析falsey和null

我试图了解如何使用默认参数对false值和null值进行解构.以下是我跑过的一些例子:

// #1
const person = { email: 'a@example.com' }
const { email = '' } = person
// email is 'a@example.com'

// #2
const person = { email: '' }
const { email = '' } = person
// email is ''

// #3
const person = { email: false }
const { email = '' } = person
// email is boolean false.  why?!

// #4
const person = { email: null }
const { email = '' …
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6

16
推荐指数
1
解决办法
8631
查看次数

标签 统计

ecmascript-6 ×1

javascript ×1