Javascript Recursive Function

Introduction

Function calls can be made recursively in JavaScript.

function factorial(number) { 
        if (number == 1) { 
           return number; 
        } //from   ww  w .j  av  a  2 s . co  m
        else { 
           return number * factorial(number-1); 
        } 
} 

console.log(factorial(5)); 



PreviousNext

Related