This article is a mirror article of machine translation, please click here to jump to the original article.

View: 13950|Reply: 1

[JavaScript] What is the difference between var a=function and function a?

[Copy link]
Posted on 6/8/2017 1:31:11 PM | | |
Javascrip{filter}t, what is the difference between var foo = function () {} and function foo() when defining functions?


Cause: Javascrip{filter}t "hoist" behavior declared by functions and variables.

Difference 1: Code 1, after loading the JS code, A is "advanced", but the specific content in the function is not advanced. It is to initialize the code block in the function when it is called. Code 2: It loads "ahead of schedule".

Method 1:

var foo = function () {     //code }

This method defines the namespace as foo to avoid duplication of method names with other libraries.

Method 2:

function foo () {     //code }

This is a general way of writing, and it is easy to create naming conflicts when using various plugins.




Previous:.net/c# Common Development Libraries (DotNetUtilities)
Next:js removes variable properties
Posted on 11/8/2017 3:18:28 PM |
Yes, I learned
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com