Using named parameters in ES6

Published

Now with ES6 you can simulate named parameters in JavaScript using the new object destructuring features.

Below is an example of a function with named parameters where all parameters are optional.

function something({ a = true, b = "something...", c = [] } = {}) {
	// do your magic here...
}

// Usage:
sendEmail({ to: "[email protected]" });

You can also combine this with positional arguments like so:

function something(a, b, { c = 1 }) {
	//...
}

Like this post?
Why don't you let me know on Twitter: @danawoodman