javascript - Why is `function() {{` legal in JS? -
this question has answer here:
i saw js of form:
function f(x) {{ return x + 1; }} to amazement, syntactically legal , works fine. @ first thought c-style anonymous scopes, not introduce new scope:
function f(x) {{ var y = x + 1; } return y;} // no error why js accept these superfluous brackets? how interpreted/what mean?
{} denotes block, or "group", of code. unless paired if statement doesn't useful. scope var determined functions in javascript, not blocks.
the new let in es6 scopes blocks.
Comments
Post a Comment