Created
October 31, 2016 04:01
-
-
Save bxt/1fca29678a16d54252454e8f954b8b4e to your computer and use it in GitHub Desktop.
Javascript (ES6) Named parameters with default values ツ
This file contains 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
// 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