Skip to content

Instantly share code, notes, and snippets.

@victorvhpg
Last active November 7, 2016 00:02
Show Gist options
  • Save victorvhpg/85dd87a382904a3a4b7d06a5e60d14ec to your computer and use it in GitHub Desktop.
Save victorvhpg/85dd87a382904a3a4b7d06a5e60d14ec to your computer and use it in GitHub Desktop.
parametro valor padrao
function teste(a, b=1, c="oi"){
console.log(b);
console.log(c);
}
teste(9); // 1,2
teste("k" ,false, "B"); //false,B
teste("a", undefined, 9); // 1,9 //undefined é considerado que o parametro não foi informado
//podemos usar expressoes como valores padroes
function getValor() {
return "oi";
}
function teste2(a, b = getValor()) {
return a + "-" + b;
}
console.log(teste2(1, 2));// 1-2
console.log(teste2(1));// 1-oi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment