Use the spread operator when potential undefined

You can use the spread operator if you don't know if a variable is undefined using [...(maybeUndefined || [])].

Example:

javascript
let erik = {}

erik['weight'] = [...(erik['weight'] || []), 75]
// erik['weight'] = [...(undefined || []), 75]
// erik{ 'weight': [75] }

erik['weight'] = [...(erik['weight'] || []), 73]
// erik['weight'] = [...([75] || []), 73]
// erik{ 'weight': [75, 73] }

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.