JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
JavaScript
function fail(msg) {
throw new Error(msg);
}
function warn(msg) {
alert("Isso não parece uma idade válida");
}
function note(msg) {
console.log(["NOTA:", msg].join(' '));
}
function converterIdade(idade) {
if (!_.isString(idade)) fail("Uma string era esperada");
var a;
note("Tentativa de converter uma idade ");
a = parseInt(idade, 10);
if (_.isNaN(a)) {
warn(["Não pode converter a idade:", idade].join(' '));
a = 0;
}
return a;
}
console.log(converterIdade("abc"));