We know that in general, a function must be called before it can be executed. As shown below, we define a function and call it. function fn(){ console.log(1); } fn(); The print result is: If we don't call it, the results we print will never be displayed. There are two most common ways to write an immediate execution function:
For example: (function fn(){ console.log(2); })() The print result is: Printing successful. The second parentheses in the immediately executed function are equivalent to calling the function. We can also pass parameters to the immediately executed function. Write the parameters we want to pass in the second () as actual parameters. as follows: (function fn(a,b){ console.log('a+b='+a+b); })(1,2) The print result is: The second method of using the immediately executed function is basically similar to the first one, so I will not go into details here. So what are the functions or benefits of executing functions immediately? Its biggest function is to create an independent scope. We know that there is no concept of private scope in This is the end of this article about JavaScript immediate execution functions. For more relevant JavaScript immediate execution function content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MySql fuzzy query json keyword retrieval solution example
>>: CSS+HTML to realize the top navigation bar function
Proxying multiple 302s with proxy_intercept_error...
Table of contents Preface Mysql case when syntax:...
The outermost boxF rotates 120 degrees, the secon...
Every qualified Linux operation and maintenance p...
Table of contents 1. Global Guard 1.1 Global fron...
First install ssh in Linux, taking centos as an e...
In MySQL, you can use the REVOKE statement to rem...
Preface The Boost library is a portable, source-c...
Preparation: 1. Install VMware workstation softwa...
Table of contents Overview Object rest attribute ...
Table of contents Advantage 1: Optimization of di...
MySQL DDL statements What is DDL, DML. DDL is dat...
First, we need to use the transform-origin attrib...
As the number of visits increases, the pressure o...
This article shares the specific code for JavaScr...