JS Code Example:
[1,2,...undefined]
throw error: Uncaught TypeError: undefined is not iterable.
but, use object destructuring
{a: 1, b: 2, ...undefined} = {a: 1, b: 2}
Why?
JS Code Example:
[1,2,...undefined]
throw error: Uncaught TypeError: undefined is not iterable.
but, use object destructuring
{a: 1, b: 2, ...undefined} = {a: 1, b: 2}
Why?
In your first line, you are unpacking a variable with the ...
syntax, called spreading and are expecting a value in that position of the array.
In your second line, you are not spreading, you're using "rest properties" but you're not expecting a value back from the spreading of undefined
, so that's why it's simply ignored and treated as empty.