Skip to content

Instantly share code, notes, and snippets.

@luchiago
Created January 8, 2020 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luchiago/0f98573b18662df5741d699c5b1ff7d3 to your computer and use it in GitHub Desktop.
Save luchiago/0f98573b18662df5741d699c5b1ff7d3 to your computer and use it in GitHub Desktop.
An use of spread operator in JavaScript
const user = {
name: 'Lucas',
lastName: 'Hiago'
};
function getUserWithFullName(user) {
return {
...user, //spead operator
fullName: `${user.name} ${user.lastName}`
}
}
const userWithFullName = getUserWithFullName(user);
console.log(userWithFullName, user);
// output: Lucas Hiago
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment