4, garbage collection mechanism:
Automatically frees up memory in JS.
var B = s.touppercase ();
S=b; After running to here, JS will automatically detect no longer use an object, because S=b, so JS will automatically release the string "Heelo" the storage space occupied. That is, we can no longer get the original "Heelo" value;.
JS is non typed. Its variables can be placed in any type of value.
Declaration of variables:
Repeated statements are legal,
If a statement is omitted, JS declares the variable implicitly. Of course, implicitly declared variables are always global variables.
6, the scope of the variable:
JS has 2 kinds: global and Local.
As you can see from the definition of the name, global variables are scoped globally.
In the JS code, there are definitions everywhere.
The scope of a local variable is local.
defined in the function body.
Local variables with the same name have higher precedence than global variables of the same name, as the following example illustrates:
var a = "abc"; Global variables
var a = "EFG"; Local variables with the same name
Look at one of the more classic examples:
alert (scope); Output undefined
alert (scope); Output Local
Why does the first one output undefined?
Because JS stipulates that the authority variables and global variable names are the same, global variables with the same name in the body of the function are hidden.
So just the example is actually equivalent to:
OK, if you read this example, you know a little bit about the difference between local and global.
7, the scope of the variable:
From the inside to the outside:
Lexical scopes
|
Scope chain
|
Variable Lookup
|
var x = 1;
function f () {
var y = 2;
function g () {
var z = 3;
}
}
|
Call the G () object; z = 3;
Call the F () object; y = 2;
global variable x = 1
|
Is it defined here?
Is
Whether
Get value
Is it defined here?
Is
Whether
Get value
Is it defined here?
Is
Whether
Get value
Not defined
|
8, client global variables:
In client JS, the Window object represents the browser windows, and he is a global object. 、
For example, our common parseint (), Math () are properties defined by the Window object.
JS allows the execution environment for multiple global variables with different global objects for each environment.
For example: The client JS each independent browser window, or the same window of different frames.
The code is run in its own execution environment and has its own global object.
Of course, you can use an expression parent.frames[0].x; To reference the global variable x in the first frame, so that the code in the different frames is connected.
But there's a security issue here.