A slight edit to Anton's code:
function fact(x) {
if(x>0)
return x* fact(x-1);
if(x===0)
return 1;
return null;
}
(factorial of a negative doesn't exist, but factorial of 0 is equal to 1, in this case, if a number is smaller than 0, the function will return null)