Home >Web Front-end >JS Tutorial >Javascript variable scope
论 Analysis: 是 Whether it is a strong type of language C#, C ++, Java and other languages, or weak types of language such as JavaScript, all variables can be abstracted into two types, namely local variables and global variables.
Global variables: The entire scope is visible. Local variables: Local visible, exit, is destroyed by GC and recycling space. Code analysis://局部变量 function PartVary() { var n = 10; //表示局部变量,外部不可访问 } PartVary(); alert(n);//error <br> //全局变量 function AllVary() { n = 10 //表示全部变量,外部可访问 } PartVary(); alert(n);//10 <br> var n = 10; function AllVary() { alert(n); } AllVary();//10Summary: Regarding the visibility of variables, those with low scope can access those with high scope, however, those with high scope cannot access those with high scope. Abstract: parent shields child