Last active
January 4, 2017 16:18
-
-
Save danieluhl/489a24d9c71993c8e5d94b336abf7287 to your computer and use it in GitHub Desktop.
Ideal way to pass params to a function ES6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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