JavaScript Advanced Knowledge Analysis--defining functions

Source: Internet
Author: User

The code information comes from http://ejohn.org/apps/learn/.

What can I use to declare a function?
return true  varreturntruereturntrue;}; Console.log (isnimble, Canfly, isdeadly); // function isnimble () function canfly () function window.isdeadly ()

In this code, we declare the global function in three ways:

1.isNimble, using a named function.

2.canFly, declare an anonymous function, assign this function to a global variable (with VAR). Depending on the nature of the function, you can use the Canfly () call.

3.isDeadly, declare an anonymous function, assign this function to the property of the Window object isdeadly, you can call this function using window.isdeadly () and deadly ().

is the order of function declarations important?
var function return true  functionreturntrue//truefunction return true; }

When a named function declaration is used, the function can be referenced at the current scope.

Where can I assign a reference?
typeof Canfly = = "undefined", "can not referto"typeof isdeadly = "undefined", "nor can"var  functionreturntruefunctionreturntrue; };

You cannot use the Declare anonymous function when you assign it to a variable.

Can I declare a function under return?
function Stealthcheck () {   Console.log (Stealth ()); // true  return Stealth ();    function return true ; } } stealthcheck ();

Sure enough, a function that uses a named declaration can be referenced anywhere in the current scope.

JavaScript Advanced Knowledge Analysis--defining 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.