Why are parentheses required around JavaScript IIFE? [duplicate]
问题 This question already has an answer here: Explain the encapsulated anonymous function syntax 10 answers I'm reading up on JavaScript IIFE and so far the understand concept, but I am wondering about the outside parenthesis. Specifically, why are they required? For example, (function() {var msg='I love JavaScript'; console.log(msg);}()); works great, but function() {var msg='I love JavaScript'; console.log(msg);}(); generates a syntax error. Why? There are lots of discussions on IIFE, but I'm