the capability of assigning function to a lvalue makes functions first-class citizen. but embedding a function into another function definition is called "closure". In this case the function is defined in a function scope, but the parent function exports (returns) the embedded function so that the embedded function can be accessed or called from the global environment. There are a few advantages of using closure, but those are all advanced use. If you wanna know more, I can probably give you some reference.
In mathematics and computer science, a higher-order function (also functional form, functional or functor) is a function that does at least one of the following:
- takes one or more functions as an input
- outputs a function
所以樓主既例子都係一個higher order function（因為佢outputs a function）