Why does my function return undefined
? Where does that come from?
function Maths(){
this.raiz = function(numero){
if(numero<0) return console.log("No disponible para números imaginarios");
return numero%1===0 ? Math.sqrt(parseInt(numero)) : Math.sqrt(parseFloat(numero));
};
}
var b = new Maths();
console.log(b.raiz(-4));
If you try to get negative root, you will return a message in console that is not available for imaginary numbers and therefore in return
, the function will end but also returns undefined
. Why?