javascript study notes four: functions (objects) in javascript

1. Functions in javascript: In js, functions are objects (he also provides local scope), because:
                        functions can be dynamically created at runtime, and can also be created during program execution.
                        Functions can be assigned to variables, their references can be copied to other variables, they can be expanded, and most functions can be deleted.
                        It can be passed to other functions as parameters, and can also be returned by other functions.
                        Functions can have their own properties and methods.

2. Function expression vs. function declaration: function declaration must have a function name, function expressions need not have function names, and function expressions are generally assigned to variables
                        1). Function declarations can only appear in "program code", It can only be in the body of other functions or in the global space.
                        2). The definition of a function declaration cannot be assigned to a variable or attribute, nor can it appear in a function call in the form of a parameter.
3. Every function has a name attribute (read-only), then this attribute only gives the name of the function. If the function is an unnamed function, the value of the name attribute of the function returned by the general browser is empty",
4. Generally speaking, we don’t want to use a named function expression to assign a value to another variable, such as:
                        var foo = function bar(){//.....}
   The value of the name attribute of this function in IE is not correct Therefore, this usage is not recommended.
5. Function promotion: For all variables, no matter where they are declared in the body of the function, they will be promoted to the top of the function in the background. This also applies to functions.

Guess you like

Origin blog.csdn.net/nanxiaotiantian/article/details/20216827