JS Basics (Functions)

Source: Internet
Author: User

function an object in which functions can be encapsulated, and when a function object is checked with typeof, it returns function

Create a Function object

var function = new function ();

The code that you want to encapsulate can be passed to the constructor in the form of a string

var function = new Function ("Console.log (' xxxxxxxx ');");;

Syntax for calling functions: Function object (), Functions ()

Use a function declaration to create a function

Grammar:

Function name (formal parameter list) {

function body;

}

Use a function expression to create a function:

Grammar:

var fun = function (formal parameter list) {

function body;

}

When invoking a function, the parser does not check the type of the argument, nor does it check the number of arguments, the extra arguments are not assigned, the number of arguments is less than the number of formal parameters, and the shape arguments without the assignment is undefined

Return is not written, it is equivalent to returning undefined, and if you do not write a return statement, you will return a undefined

Return value can be any type, can be an object, or it can be a function

function Fun3 () {    // inside the function, declare a functions     fun4 () {        alert ("  I am fun4");    }                  // returns the Fun4 function object as a return value    return  = fun3 (); // a (); Fun3 () ();    

Execute the function immediately:

function () {    alert ("xxxxxx");} // the above is the wrong wording
(function () {    alert ("xxxxxx");}) (); // Execute now

JS Basics (Functions)

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.