I don't understand about spread syntax inside objects.
console.log(...false) // TypeError not iterable
console.log(...1) // TypeError not iterable
console.log(...null) // TypeError not iterable
console.log(...undefined) // TypeError not iterable
I understand above codes that occurs error because of none-iterator.
But these codes are working well.
console.log({...false}) // {}
console.log({...1}) // {}
console.log({...null}) // {}
console.log({...undefined}) // {}
Please let me know why the above codes are working.
I don't understand about spread syntax inside objects.
console.log(...false) // TypeError not iterable
console.log(...1) // TypeError not iterable
console.log(...null) // TypeError not iterable
console.log(...undefined) // TypeError not iterable
I understand above codes that occurs error because of none-iterator.
But these codes are working well.
console.log({...false}) // {}
console.log({...1}) // {}
console.log({...null}) // {}
console.log({...undefined}) // {}
Please let me know why the above codes are working.
Share Improve this question edited Mar 11, 2021 at 8:58 mikemaccana 123k110 gold badges427 silver badges531 bronze badges asked Oct 30, 2020 at 6:13 kkangilkkangil 1,7464 gold badges16 silver badges27 bronze badges 1
"use strict"; Object.defineProperty(Number.prototype, Symbol.iterator, { enumerable: false, configurable: true, writable: true, value: ({ [Symbol.iterator]: function*(){ for(let i = 0; i < Math.abs(this); ++i){ yield i * (this < 0 ? -1 : 1); } } })[Symbol.iterator] });
to makeconsole.log(...1)
work.