Created
August 5, 2013 20:41
-
-
Save marciojrtorres/6159425 to your computer and use it in GitHub Desktop.
Arrumando a casa com técnicas de programação defensiva
This file contains 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 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