The recent understanding of JavaScript has given me a different feeling. There’s a lot of resonance! This time I heard some insights about different types of functions to share with you
The following example is a function named box, with no parameters, returning Lee, and alert is the output function
1 2 3 4 |
|
The following example is an anonymous function. The difference from an ordinary function is that it has no name, so when we only write an anonymous function, it cannot be executed because it has no name. , cannot use alert
1 2 3 |
|
because we have an anonymous function Unable to run, so we assign the anonymous function to a variable and run our anonymous function indirectly through the variable
1 2 3 4 5 |
|
1 2 3 |
|
1 2 3 |
|
1 2 3 |
|
Closure means to put a function inside the function and then display
1 2 3 4 5 6 |
|
The local variables of the function cannot be accumulated because it uses global variables. Global variables cannot be saved in memory, but closures can accumulate, and closures can accumulate local variables. Local variables can be saved in memory, so they can be accumulated, but local variables can be used frequently because they occupy too much memory.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Study seriously! Don’t ask for progress! Seeking the best! Everything is knowledge, it depends on whether you want to learn it or not!
The above is the detailed content of Different kinds of functions in JavaScript. For more information, please follow other related articles on the PHP Chinese website!