I'm going down the es6 compatibility table trying to learn Here.
in the bindings section it says "block-level function declaration?". I'm unable to find any blogs or documentation besides the offical spec on that combinations of words.
Question: What is "block-level function declaration" referring to?
the example kangax is testing for:
alert(function(){
'use strict';
function f() { return 1; }
{
function f() { return 2; }
}
return f() === 1;
}());
it means that function "hoisting" behaves the same way as let
(vs var
).
In ES5, braces were "decoration", unless they appeared after a few keywords like for
, if
, try
, etc. so, the 2nd f()
would "clobber" the 1st, but in ES6-compat runtimes, the 2nd f()
is private to the block and thus doesn't replace the name f
defined by the 1st function.
In ES6 braces ({ ... }
) mean a block, even without a preceding keyword. That said, i don't see many arbitrary blocks in ES6 code, maybe just from lack of practice, ignorance, or perhaps just from lack of need; function scope works pretty well in JS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With