What does JavaScript function promotion refer to?
This article mainly introduces the relevant knowledge of what JavaScript function promotion refers to, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value, I believe you will gain something after reading this JavaScript function promotion refers to what article, let's take a look at it.
Function promotion (Hoisting)
Hoisting is the behavior that JavaScript promotes the current scope to the front by default.
Hoisting is applied to the declaration of variables and functions.
Therefore, the function can be called before the declaration:
MyFunction (5)
Function myFunction (y) {
Return yellowy
}
Cannot be promoted when using an expression to define a function.
Self-calling function
Function expressions can be "self-calling".
The self-calling expression is called automatically.
If the expression is followed by (), it is called automatically.
A declared function cannot be called by itself.
Indicate that it is a function expression by adding parentheses:
Case study
(function () {
Var x = "Hellobirds!"; / / I will call myself
) ()
This is the end of the article on "what does the promotion of JavaScript function mean?" Thank you for reading! I believe you all have a certain understanding of the knowledge of "what JavaScript function promotion refers to". If you want to learn more knowledge, you are welcome to follow the industry information channel.