文档介绍::..js变量作用域Eachlanguagehastheconceptofvariable,,thefollowingfunction:lfunction,Student(name,age,from)2{=name:4this・age=age;5this・from=from;=function(){78return,z,my,information,is,name:z,,〃++〃,〃age〃,〃++〃, +this・from;9}10}TheStudentclasshasthreevariables,name(name),age(age),andfrom(nativeplace)・Thesethreevariablesmakeuptheinformationdescribinganobject・Ofcourse,thereisalsoawaytoreturninformationfromStudent・essedandusedanywhereuntilitisdestroyed?Thinkcarefully,theaboverequirementisexcessive,becausesomeofthevariablesinafunctionisnolongerused,butifthevariablesstillexist,takeupsystemresources,theysaid:"stoodMaokengnotpull#$%〃・Sowehaveadiscussiononthetimelyandon-demanddestructionofvariables・Well,let'sgetdowntothepoint・AsfarasI'mconcerned,JSsupportsseveraltypesofvariables:localvariables,classvariables,privatevariables,instancevariables,staticvariables,andglobalvariables・Next,:Localvariablesgenerallyreferstotheeffectivevariablesintherangeofvariablesis{},effectivestatementsinsidetheblock,suchas:lfunctionfoo(flag)2{3varsum二0;4if(flag二true)6varindex;7for(index=0;index<10;index++)(89sum+二index;10}11}("indexis":〃+index+〃,/<br>,/);13returnsum;14}15//("sumis":〃+sum+〃〃〈br〉〃);("resultis〃:〃+foo〃(true)+,z<br>z,);Whenthecodeisexecuted,theoutputresultsare:,zindexis:undefined〃and"resultis:0〃・Wecanseethatthevalueoftheindexvariablethatwewanttooutputisundefined,thatis,undefined・Sowecanseethattheindexvariableisdestroyedaftertheendoftheifstatementblock・Whataboutthe"sunTvariables?Thisvariableisdestroyedaftertheexecutionofthefoo()functionsection・IfyouremovethestatementIarmotated,andthenexecute,youwillfindthatthesystemwillbewrong・ItisworthnotingthatifIchangetheabovefoo()functiontothefollowing:lfunctionfoo(flag)2{3varsum二0;4for(VaRindex=0;index<10;index++;){56sum+二index;7}