Is it possible to call another function: ======================================== function f1() { body of statements for implementation f2() } function f2(){ statements with implementation f1() } Calculator: =========== Arithmetic Logarithms log(a) + log(b) log(a+b) Trigonometry Integration Differentiations f1() { addition } f2() { log f1(a,b) log(result_f1) } // Calling a function inside another function let sum = function(a,b,c,d,e) { var result = a+b+c+d+e; return result; } var average = function(a,b,c,d,e) { avg = sum(a,b,c,d,e) / 5; console.log("The Average = "+avg); } var s = sum(12,13,14,15,16); console.log("The Sum = "+s); average(12,13,14,15,16); ======================================= Q: WAP to find the factorial of the number. =========================================== // A PROGRAM TO FIND THE FACTORIAL OF THE NUMBER. let factorial = function(n) { var fact = 1; if(n == 0) { return fact; } else if(n > 0) { num = n; while(num > 0) { fact = fact * num; // 7 42 210 num--; // 6 5 } return fact; } else { return "Factorial is not possible"; } } console.log("The Factorial = "+factorial(-7)); ============================================== Recursion: ========== ==> Recursion Function ======================= ==> the function for the recursion, "recursion function" ==> Recursion ============== ==> a process that can call the same function itself again and again until the completion of process. let factorial = function(n) { let fact = 1; if(n == 0) { return fact; } else if(n > 0) { return n * factorial(n-1); } else{ return "factorial is not possible."; } } console.log("The Factorial = "+factorial(6)); Syntax: function f1() { implementation; f1(); } =============================================== Pure Functions: =============== 1) Debugging is easy 2) Testing is easy. 3) Writing of Unit test cases easy. let/var identifier = function(parameters) { // can perform the action with only parameters. doesn't access the external values // cannot allow to modify the content of parameters } ======================= // var a; let addition = function(a,b,c) { // a = 100; // b = 200; // c = 300; return a+b+c; } console.log("The Sum = "+addition(10,20,30));