I. Description of KNOWLEDGE
function Fun () { // own call itself, called recursive call fun (); Console.log ("m2");} Fun ();
Second, function + variable
// to find the factorial of 5 with a recursive return // n! = n * (n-1)! // defines a function that is used to find the factorial of n function func (n) { if (n = =1 ) {return 1; } // func (n-1) because the parameter passed is n-1, then it is the factorial of (n-1) return N * func (n-1);} Console.log ( func (5) );
Third, function + function
// retracement question (Rabbit-born rabbit title )--From the 3rd month after birth of a pair of rabbits every month, the small rabbit to the third month after the birth of a pair of rabbits, if the rabbit is not dead, ask the number of rabbits each month is how many // Span style= "COLOR: #008000" > yield analysis: 1, 1, 2, 3, 5, 8, 13, 21 ... // The number of rabbits in the nth month = total number of rabbits in n-1 month + total number of rabbits in n-2 months // question: Total number of rabbits for any month function func (n) { if (n = = 0 | | n = = 1 return 1; return func (n-1) + func (n-2 var a = func (22
JS function recursion