Tail Recursion | A tail recursive function to calculate factorial ; A wrapper over factTR ; Driver code
function factTR ( n , a ) { if ( n == 0 ) return a ; return factTR ( n - 1 , n * a ) ; } function fact ( n ) { return factTR ( n , 1 ) ; } document . write ( fact ( 5 ) ) ;