There are two ways to declare functions in javascript: function declarations and function expressions.
The difference is as follows:
1. Functions defined by the method declared by the function, the function name is required, and the fu
There are two ways to declare a function in JavaScript: function declaration and function expression.The difference is as follows:1). A function that is defined by a method declared by a function, the
Give an example:
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Just try to know that this code means to declare a function and execute it immediately, because the variable scope in JavaScript is based on functions, so it avoids variable contamination, but here the bitwise operator "~" At first glance is confusing. If you remove it and
In JavaScript, functions are defined in two ways, function definition expressions and function declarations, as shown in the following examples:var test = function (x) {return x;}function test (x) {return x;}Although function defi
() { console.log.apply (console, arguments);};1.3.3 The reason is that the parser reads the two definitions in a different order, the parser reads the function declaration in advance and makes it available before executing the subsequent code, whereas for a function expression, the parser executes only when it reads the line where the
When I read another blog today, I found thatArticleI have been talking about function declarations and function expressions,
I was a little dizzy, and I sorted it out later. In fact, these two concepts have been used before, but they are not noticed!
1.
Function declaration:
FunctionA () {alert ("Hello World")}//This is a
Or the same, first code:
Copy Code code as follows:
Throwing this code into IE 6 and chorme is a completely different two-way effect.
Output 2 Here is the effect in IE6, if G is not defined in Chorme.
This is also a JScript bug.
It is obvious here that only the function expression of g is defined here. Included in the conditional statement of if, only the
function is the result of the variable, which is stored in the global context variable (available window. function name to validate)
2: This way is the function declaration, which is created in the global context phase, and is already available in the code execution phase. Ps:javascript initializes the context environment (by global → Local) Every time the meth
The function declaration in JS refers to the following form:
function functionname () {
}
This way to declare a function, and a function expression is like an expression to declare a
1. The first is the function statement:MyFunc (); function MyFunc () { //execute some statements}When a function statement is defined, it is preferred in a script code, so that the function can be used by the script, either before or after the definition, as in the above statement.2.
Objective
When you learn JavaScript, you often encounter the code to execute anonymous functions, today we mainly come to think about the implementation.
Before we get to the details, let's talk about the term "self-execution," this article on the name of this function is not necessarily completely right, mainly to see how the individual understand, because some people say immediately call, and some people
This article comes from Uncle TomObjectiveWhen you learn JavaScript, you often encounter code that executes anonymous functions, and today we mostly think about self-executing.Before learning more about this, let's talk about the "self-implementation" of the term, this article is not necessarily the name of the function is not entirely right, mainly to see how the individual understand, because some people
There are two main methods of creating functions in javascript: function declarations and function expressions. Both of these methods have different scenarios. The main focus of this note is on several features of the function expression and its usage scenarios, which are de
function declaration requires a name.Narrator: function, parentheses (paren), syntax error (SYNTAXERROR)Interestingly, even if you add a name to the wrong code above, he will also prompt for grammatical errors, except for the reasons above. After an expression with parentheses (), the expression executes immediately,
This article describes how to execute function expression IIFE in javascript. It has good reference value. let's take a look at it below. This article mainly introduces the knowledge of javascript immediate execution function expression
() {
alert (this.name1);
}
}} Obj.fun3 () ();
var obj2 = {};
obj2.name1 = "Test";
Obj2.fun = Obj.fun3 ();
The Obj2.fun ()///Print result "test" proves again "which object points out the method, this is which object".
var name1 = "John";
var obj = {
name1: "Dick",
fun2:function () {
alert (this.name1);
},
fun3:function () {
return function
Explain how to execute the function expression IIFE and javascriptiife in javascript immediately
I. IIFE explanation
Fully spell Imdiately Invoked Function Expression, the Function Expression
function declaration, function expression, anonymous function: function declaration: Functions fnname () {...}; Declare a function using the function keyword, and then specify a name fo
Today, the main review of the "JavaScript Advanced program" function expression in this chapter, mainly their own closure and this concept or not clear, resulting in a small demo when this piece of the completion of ignorance, first do a knowledge comb, and then continue to strengthen practice it. characteristics of function
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.