The Problem here is that with the output coming JavaScript also says undefined. I have seen some codes on w3schools.com and developers.mozilla websites and tried some other sites also but didn't find any solution or any explanation about the problem that i encounter.
I want to throw an exception when 0 or negative value occur.
function isPositive(a) {
try {
if (a > 0) return "YES";
if (a < 0) throw "Negative Value";
if (a == 0) throw "Zero Value";
} catch (error) {
console.log(error);
}
}
console.log(isPositive(0));
Output expected was
"Zero Value"
Actual Output is
"Zero Value"
undefined
Any suggestions why my code prints undefined along with the output? Thanks in Advance.
try?console.login that code. What do you expect the second one to log?