Javascript ES6 spread operator on undefined [duplicate]

This behavior is useful for doing something like optional spreading: function foo(options) { const bar = { baz: 1, …(options && options.bar) // options and bar can be undefined } } And it gets even better with optional chaining, which is in Stage 4 now (and already available in TypeScript 3.7+): function foo(options) { const … Read more

Deep copy in ES6 using the spread syntax

Use JSON for deep copy var newObject = JSON.parse(JSON.stringify(oldObject)) var oldObject = { name: ‘A’, address: { street: ‘Station Road’, city: ‘Pune’ } } var newObject = JSON.parse(JSON.stringify(oldObject)); newObject.address.city = ‘Delhi’; console.log(‘newObject’); console.log(newObject); console.log(‘oldObject’); console.log(oldObject);

Using spread syntax and new Set() with typescript

Update: With Typescript 2.3, you can now add “downlevelIteration”: true to your tsconfig, and this will work while targeting ES5. The downside of downlevelIteration is that TS will have to inject quite a bit of boilerplate when transpiling. The single line from the question transpiles with 21 lines of added boilerplate: (as of Typescript 2.6.1) … Read more

What are these three dots in React doing?

That’s property spread notation. It was added in ES2018 (spread for arrays/iterables was earlier, ES2015), but it’s been supported in React projects for a long time via transpilation (as “JSX spread attributes” even though you could do it elsewhere, too, not just attributes). {…this.props} spreads out the “own” enumerable properties in props as discrete properties … Read more