Skip to content

Instantly share code, notes, and snippets.

@danieluhl
Last active January 4, 2017 16:18
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 danieluhl/489a24d9c71993c8e5d94b336abf7287 to your computer and use it in GitHub Desktop.
Save danieluhl/489a24d9c71993c8e5d94b336abf7287 to your computer and use it in GitHub Desktop.
Ideal way to pass params to a function ES6
// functions take parameters in any order and set defaults
const greetPerson = ({first = 'Saw', last = 'Gerrera'}) => `Hello ${first}! Sorry, I meant Dr. ${last}`;
// objects or properties can be built however
const person = {
first: 'Cassian',
last: 'Andor',
birthday: '04/04',
age: '23',
position: 'Pilot'
};
// pass an object in that has the params, this may not be ideal because it's not clear what params the function takes
greetPerson(person);
const first = 'Jyn';
const last = 'Erso';
// or pass individual params
greetPerson({first, last});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment