I have the following code but it is not giving perfect result for factorial can u find it out plz
i am quite new to javascript and would be happy to know any improvements that could be made to this answer
var a = 1;
function factorial(num) {
if (num == 0) {
return 1;
} else if (num < 0) {
return undefined;
} else {
for(i = num; i > 0; i--){
a *= i;
}
return a;
}
}
var b = factorial(5);
console.log(b);