JavaScript Nested Function : A function can also contain another function. This is called nested function. function greet ( name ) { function displayName () { console . log ( " Hi " + name ) } displayName (); } greet ( " Varun " ); Output : Hi Varun Enter fullscreen mode Exit fullscreen mode Returning a function : In JavaScript, it is allowed to return a function within a function. function greet ( name ) { function displayName () { console . log ( " Hi " + name ) } return displayName ; //returning a function } const g1 = greet ( " Varun " ); console . log ( g1 ); g1 (); Output : displayName () { console . log ( " Hi " + name ) } Hi Varun Enter fullscreen mode Exit fullscreen mode In the above program, the greet() function is returning the displayName function definition . The returned function definition is assigned to the g1 variable. When you print g1 using console.log(g1), you will get the function definition. To call the function stored in the g1 variable, we use g1() with parentheses.…