JS basic grammar --- Scope

Scope: scope

 

  • Global variables: The variable is declared using the var statement, this variable is a global variable
  • Global variables can be used anywhere on the page
  • In addition to function, any other location defined variables are global variables
  • Local variables: the variables defined within the function, is a local variable, it can not be used outside
  • Global variables, if the page does not close, then it will not release, it will take up space, consumes memory
  1. Global scope: use of global variables
  2. The local scope: the use of local variables
  3. Block-level scope: a pair of braces can be seen as a variable defined in this area, only in this region
  4. However js defined in scope as the block level, it can also be used outside. Description: js not block-level scope, with the exception of the function

 

  •  Implicit global variables: variable declaration is not var, called an implicit global variables
  •  Global variables can not be deleted, implicit global variables can be deleted
  •  The definition of variables var is not deleted, there is no var can be deleted
      function F1 () { 
        Number = 1000; // implicit global variable 
      } 
      F1 (); 
      the console.log (Number);

 

 

Guess you like

Origin www.cnblogs.com/jane-panyiyun/p/11950646.html