Javascript learning notes (2) JavaScript core variables

Source: Internet
Author: User
Tags variable scope

Javascript is non-typed, which means that its variables can store any type of values. It can be converted quickly and automatically if necessary.
Variable Declaration uses var. a var statement can declare multiple variables and separate them with commas. It can also bind the variable declaration with the variable initialization.
Repeated declaration and missing Declaration: var multiple declarations of the same variable are legal. An error occurs when you try to read the value of an undeclared variable. If you assign a value to a variable that is not declared by VAR, JavaScript will implicitly declare the variable, however, variables declared implicitly are always created as global variables. Therefore, we recommend that you use the VaR statement to create global or local variables. For example:
Scope = "Global"; // declare a global variable
Function checkscope (){
Scope = "local"; // The global variable is changed.
Document. Write (scope); // The global variable is used.
Myscope = "local"; // implicitly declare the new global variable
Document. Write (myscope); // use the new global variable
}
Checkscope (); // output "locallocal"
Document. Write (scope); // output "local"
Document. Write (myscope); // output "local"
Function definition can be nested
No block-level scope
Undefined and unassigned variables: an error occurs when you read undeclared variables. When you read declared but unassigned variables, the default value undefined is obtained.
Basic type and reference type: Values, Boolean values, null and undefined values belong to the basic type, objects, arrays, and functions belong to the reference type.
Collection of useless storage units: it is automatic and invisible. For example:
VaR S = "hello"; // allocate memory space for a string
VaR u = S. touppercase (); // create a new string
S = u; // overwrite the reference to the original string
As a property variable: the variable is basically the same as the object property.
Global Object: When the javascript interpreter starts running, a global object is created first. The attribute of this object is Program .
Local variable: Call object. When executing a function, the function parameters and local variables are stored as the properties of the called object.
Javascript execution environment:
Deep understanding of variable scope: Scope chain and variable Parsing

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.