Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marciojrtorres/6159425 to your computer and use it in GitHub Desktop.
Save marciojrtorres/6159425 to your computer and use it in GitHub Desktop.
Arrumando a casa com técnicas de programação defensiva
function dobro(n) {
if (typeof(n) != "number") return 0; // se n não é um número retorne 0
return n * 2;
}
document.write(dobro(2)); // ok, imprime 4
document.write(dobro("t")); // ok, "t" não é do tipo number, então imprime 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment