Skip to content

Instantly share code, notes, and snippets.

@victorvhpg
Last active November 8, 2016 01:20
Show Gist options
  • Save victorvhpg/f682e715da365c1fef014399c6b47deb to your computer and use it in GitHub Desktop.
Save victorvhpg/f682e715da365c1fef014399c6b47deb to your computer and use it in GitHub Desktop.
//com parametro nomeado opcional
function teste(a, { b, c = 5}){
console.log(a);
console.log(b);
console.log(c);
};
teste(1, { b: "oi" }); //1, "oi", 5
teste(99, { b: "oi", c: "aa" }); //99, "oi", aa
teste(1); //TypeError .... pois não passou o objeto
// objeto opcional
function teste(a, { b, c = 5} = {}){
console.log(a);
console.log(b);
console.log(c);
};
teste(2); //2,undefined,5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment