function c(n) {
var v;
if (n % 1 !== 0) v = parseFloat(n); // Verifico si el numero es decimal y uso parseFloat
else v = parseInt(n); // Verifico si el numero es entero y uso parseInt
return v; // Retorno el numero
}
console.log(c("45.2")); // Llamo a la función
Assuming that JavaScript
did not transform the string
into numbers, how could you verify that n%1
, if it were first would be a string
?