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

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -