Reputation: 1087
Can someone please help me understand how to call this JS function expression
var math = {
'factorial': function factorial(n) {
if (n <= 1)
return 1;
return n * factorial(n - 1);
}
};
Upvotes: 0
Views: 76
Reputation: 7994
Here you go. Should be self-evident:
var math =
{
'factorial': function factorial(n)
{
if (n <= 1)
return 1;
return n * factorial(n - 1);
}
};
var result = math.factorial(3);
// For the purposes of illustration, we will use document.write to output
// the result. document.write is generally not a good idea, however!
document.write(result);
Upvotes: 1