destructuring default value use
||
, without undefined only
yarn add babel-plugin-use-or-operator-for-destructuring-default-value
const user = {name: 'xiaohesong', age: null, sex: ''}
const {name, age = 18, sex = 'man'} = user
console.log(name, age, sex) // xiaohesong null
const user = {name: 'xiaohesong', age: null, sex: ''}
const {name, age = 18, sex = 'man'} = user
console.log(name, age, sex) // xiaohesong 18 man
Give a ⭐️ if this project helped you!