About javascript function

I found weird behavior in Javascript:

function() { return 10; }(); 

This design does not work in all browsers because it has a syntax error. But this construction works (ten returns):

 +function() { return 10; }(); 

Why?

+4
source share
1 answer

+ allows the js mechanism to make the difference between this function expression and the function definition.

For readability, we usually use

 (function() { return 10; })(); 

See related article

+2
source

All Articles