问题描述:

This question already has an answer here:

  • What does the exclamation mark do before the function?

    7 answers

网友答案:

The 'executing' parens at the end can't be done legally after a function expression. A typical (more sensical, IMO) way of writing this is with more parentheses:

(function(){console.log('hi')})()

By prepending the ! before the function expression, the JS interpreter reads the function and then runs it. This is because of the precedence of the ! operator vs. calling a function with the final ()

网友答案:

Look at this answer

tl;dr it defines a function to print out 'hi' and immediately calls it.

相关阅读:
Top