Taken at face value, statement:
Function declarations occur as standalone constructs and cannot be nested inside non-functional blocks.
wrong. As examples in the article, you can place function declarations inside blocks. The reason he warns is because the behavior is different in different browsers. In most browsers (unspecified versions of IE and Firefox), such functions are declared regardless of whether execution is in the block or not, for example:
if (false) { function foo(){} }
foo is declared and available in the outside area. This is exactly the same as variable declarations:
if (false) { var x = 3; }
In the above, x is declared regardless of whether the block is running or not. However, the assignment of a value occurs only when a block is entered.
Back to features. The declaration of the function of the cause function in blocks is warned that, firstly, this means that the function is created only when the block is entered, which is not true for most browsers, but not for all. Secondly, and more importantly, because different browsers have different behavior.
Interesting reading:
Also note that function statements are warned in ES5 strict mode and may be introduced in some future version of ECMAScript.
Finally, this behavior is addressed directly in ECMA-262 ed 6 in Appendix B 3.3.3 and Appendix B 3.4 .
source share