IS IT POSSIBLE TO DEFINE THE FUNCTION IN ANOTHER FUNCTION: ========================================================== // Nested Functions let square = function(x) // outer function { var s = x * x; let cube = function(x) // inner function { var c = s * x; console.log("The Cube = "+c); } cube(x); return s; } result = square(8); console.log("The Square = "+result); // cube(7); ======================================================= 9876 = 9+8+7+6 ============== f1() { f2() { get individual digits } sum_of_digits } ============================== let sum_digits = function(num) { let ind_digits = function() { i = num; while(i != 0) { rem = i % 10; } return rem; } let s = 0; s += ind_digits(); i = Math.floor(i / 10); console.log("The sum = "+s); } sum_digits(876543); ========================================= Callback Function: ================== Sending a function as an argument to another function is called as "callback function". ==> the function can be perform the operation after the another function. Syntax: function fun1(f2) { implementation } function f2() { implementation } fun1(f2) setTimeout(): ============ function f1(f2) { console.log("Hi"); console.log("Hello"); setTimeout(function(){ f2(),1000 }) } function f2(result) { console.log("Welcome to Ashok IT."); } f1(f2); ================================ currying: ========= f1(x,y,z) { return x * y * Z; } f1(x) { return function(y) { return function(z) { return x * y * z; } } } function volume(length) { return function(breadth) { return function(height) { return length * breadth * height; } } } console.log("The Volume = "+volume(4)(5)(6));