I would like to see examples of using a functional level area that would be more difficult or impossible to implement using a block level area.
This may sound obvious, but you can implement recursion in the area of โโthe functional level, which can often be useful, for example:
var x = 5; // global scope (function (y) { // y - locally scoped variable on each execution y && arguments.callee(--y); // recursion! console.log(y); })(x);
This is almost impossible to implement with a block level area.
In the above example, a function will be executed first, passing it the value of the external variable x , before the function is called, a new execution context will be set up, which initializes a new lexical region, where y formal parameter associated with it.
After that, the function expression is executed again. -if y not 0 - initialization at each execution of a completely new lexical area.
CMS
source share