Skip to content

Instantly share code, notes, and snippets.

@bxt
Created October 31, 2016 04:01
Show Gist options
  • Save bxt/1fca29678a16d54252454e8f954b8b4e to your computer and use it in GitHub Desktop.
Save bxt/1fca29678a16d54252454e8f954b8b4e to your computer and use it in GitHub Desktop.
Javascript (ES6) Named parameters with default values ツ
// I just figured out you could do this in ES6:
function foo ({ a = 3, b = 5 } = {}) {
console.log(a, b);
}
foo() // => 3 5
foo({a: 0}) // => 0 5
foo({b: 0}) // => 3 0
foo({a: 4, b: 6}) // => 4 6
// --> Named parameters with default values! ツ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment