js-local variable + global variable + closure __JS

Source: Internet
Author: User

What is a variable.


Variables: We literally think of variables as variable amounts, which, in a programmatic sense, can be understood as a warehouse, where some values are stored, and as shown above, a generous box can be considered a warehouse, and a warehouse can hold all kinds of items. The variable name is the name of the warehouse.

The naming specification for variables:

1. The variable name must begin with the letter. Subscript Sign "_" or "$";

2. The length of the variable name shall not exceed 255 characters;

3, the variable name can not use a space, and the beginning must not start with a number;

4, do not use the script language reserved keywords and reserved symbols as variable names;

5, variable names are case-sensitive, Var a=1 and Var a=1;


Locals (local variables)

A variable that can be accessed in a program only in a particular procedure or function. Local variables are relative to global variables. In object-oriented languages, only local variables are generally used. Object-oriented programming is now commonly used in software development methods, so no need to consider whether local variables or global variables, when it comes to variables, are often local variables.

In language-oriented languages such as C, local variables can have the same name as global variables, but local variables mask global variables. When referencing this variable within a function, local variables with the same name are used, and global variables are not used.

<! DOCTYPE html>

Global variable variables are divided into local and global, and local variables can be called internal variables. Variables created by an object or a function are usually local variables that can only be referenced internally and cannot be referenced by other objects or functions. Global variables can be created either by an object function or anywhere in this program. Global variables can be referenced by all objects or functions of this program. A local variable is a null value when it is referenced by another object. However, this is not the case for global variables.
<! DOCTYPE html> Closed Bag

The so-called closure, simple understanding is that the child function using the parent function of local variables;

<! DOCTYPE html> var a=10;
function bb () {
alert (a);
}
return BB;
}
var result=aa ();
Result (); Pop-up </script>

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.