Last active
November 7, 2016 00:02
-
-
Save victorvhpg/85dd87a382904a3a4b7d06a5e60d14ec to your computer and use it in GitHub Desktop.
parametro valor padrao
This file contains hidden or 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
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