JavaScript function Explained

Source: Internet
Author: User

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

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.