Skip to content

Instantly share code, notes, and snippets.

@DanielMSchmidt
Last active April 13, 2016 20:19
Show Gist options
  • Save DanielMSchmidt/e7896de8933f542f0fb5e91a1a6aa22a to your computer and use it in GitHub Desktop.
Save DanielMSchmidt/e7896de8933f542f0fb5e91a1a6aa22a to your computer and use it in GitHub Desktop.
optional function parameters
function foo(a,b,c,d,e) {
//...
}
// place a
foo(1,2,3,undefined,5);
// place b
foo(1,2,3,4);
// place c
foo(42);
// Voila, the default values are all inclusive
function foo({a=1, b={}, c=[], d=42, e=3}) {
//...
}
// place a
foo({a: 1, b: 2, c: 3, d: 5});
// place b
foo({a:1, b: 2, c: 3, d: 4});
// place c
foo({a: 42});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment