PHP programmer JavaScript is necessary to do, but the real JavaScript is very advanced Ah, tell me about my study record it!
1. Semicolons are used to separate executable JavaScript statements, because the function declaration is not an executable statement, so it does not end with a semicolon.
2. Functions stored in variables do not require a function name and are usually called by a variable.
Example: var x = function (b) {return a * b};
var z = x (4,3);
The resulting result is Z = 12
3. Functions can also be defined by a built-in constructor.
Example: var myFunction = new Function ("A", "B", "return A * b");
var x = myFunction (4,3);
The resulting result is x = 12
Note: In JavaScript, there are times when you need to avoid using the new keyword.
4. There are methods and properties in the JavaScript function, and the arguments.length Zodiac returns the number of arguments received by the function.
Example: Function MyFunction (A, b) {
return arguments.length;
}
x = MyFunction (4,3)
The resulting result is x = 2
5. The toString () method returns the function as a string.
Example: function MyFunction () {
RERUTN A * b;
}
var txt = myfunction.tostring ();
The result is txt = function myFunction (A, b) {rerutn A * C};
6. If the function is missing a parameter at the time of invocation, the parameter is set by default to: undefined
This is sometimes acceptable, but it is recommended that you set a default value for the parameter
If too many arguments are set when the function is called, the parameter cannot be referenced because the corresponding parameter name cannot be found. Only the arguments object can be used to invoke.
7. The Page object in the browser is the browser window (the Window object). The function above will automatically become a function of the Window object
MyFunction () and window.myfunction () are the same.
8. The difference between call and apply is the second parameter: Apply passes in an array of parameters, which is the combination of multiple parameters into an array, and call is passed as a call parameter
9. A variable declaration is a global variable if the var keyword is not used, even if it is defined within a function.
JavaScript supports nested functions, and can access the properties and methods of the previous-level domain.
JavaScript function Explained