javascript - Why is `function() {{` legal in JS? -


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

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -