3 ms·
I think functional scope was a step forward from block scope, so I got very sad when block scope got into JavaScript and is now the standard. JS still allow you
by z3t4 8y ago
I think functional scope was a step forward from block scope, so I got very sad when block scope got into JavaScript and is now the standard. JS still allow you to use function scope, and I still do, but most tutorials now use block scope.
With function scope I can declare variables where they are used, they will be automatically hoisted. This also solves the issue with using a variable before they are declared ... you declare variables where they are used.
Function scope also encourages the use of functions and closures, which makes (async) programing more fun.