Recursive Functions
Recursive Functions
Recursion refers to a situation, wherein functions call themselves. In other words, there is a call
to a specific function from within the same function. Such functions are known as Recursive
Functions.
Example:
<html>
<head><title></title>
<script language="javascript">
function fun1(number)
{
if(number>1)
{
return number*fun1(number-1)
}
else
{
return number
}
}
var a
a=fun1(4)
document.write("The factorial of a number is "+a)
</script>
</body>
</body>
</html>
Output:
The factorial of a number is 24