0

I've inherited a project with some Java Script. I know nothing about js. There are some auto-build steps involved, the result of which is an anonymous function. The version is version control is different from the version I build, even though the environments were supposed to be the same.

One version is, void parameter list inside the evaluation brackets:

(function(){...}( )) 

The other version is, void parameter list outside the evaluation brackets:

(function(){...} ) ( )

Are these two forms technically the same? Is one form technically an error? Is either form actually an error? Or what?

david
  • 2,435
  • 1
  • 21
  • 33

1 Answers1

1

In this case, both are equivalent and valid.

Note that for the first option, when the outer parentheses are excluded, that will result in a SyntaxError

function(){...}() // error
(function(){...}()) // no error
(function(){...})() // no error
Samathingamajig
  • 11,839
  • 3
  • 12
  • 34
  • I didn't find the previous question, but now that I have, I still like your answer. It says exactly the same thing as the accepted answer in that question, but your's shorter, clearer, and easier to understand. Appropriate for a person who knows no js. – david Jul 27 '22 at 00:55