Skip to content

Instantly share code, notes, and snippets.

@townivan
Last active October 10, 2019 15:36
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 townivan/7a2b3dca7854fd5dbf541b571c82b59e to your computer and use it in GitHub Desktop.
Save townivan/7a2b3dca7854fd5dbf541b571c82b59e to your computer and use it in GitHub Desktop.
/**
* Be amazed at this use for destructuring
* If you pass args as an obj instead of
* distinct values like f('red','male',23)
* You can use destructuring in the function
* to get what you want without needing to
* figure out which position it should be in!
*/
function f( {name, age} = {}){ // destructure the received {} to name and age.
console.log('age:',age); // age: 23
}
f({color:'red', gender:'male', age:23})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment