Clean Code in JavaScript by James Padolsey

Clean Code in JavaScript by James Padolsey

Author:James Padolsey [James Padolsey]
Language: eng
Format: epub
Tags: COM060160 - COMPUTERS / Web / Web Programming, COM070000 - COMPUTERS / User Interfaces, COM051300 - COMPUTERS / Programming / Algorithms
Publisher: Packt
Published: 2020-01-17T13:13:58+00:00


// Reconstruction:

const skyline = {name, ...attributes};

skyline; // => { name: "Nissan Skyline", engineSize: "2500cc", year: 2009 }

When used in this context, the value of the right side of the spread syntax must be either an object or a primitive that can be wrapped as an object (for example, Number or String). This means that all values in JavaScript are permissible except null and undefined, both of which, as we know, cannot be wrapped as objects:

let {...stuff} = null; // => TypeError

It's, therefore, best to only use the spread syntax in an object context when you're confident that the value is an object.

In conclusion, the spread syntax, as we've seen, is remarkably useful in a variety of different situations. Its main advantage is that it reduces the amount of syntax required to extract and designate values.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.