前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >javascript当中局部变量和全局变量

javascript当中局部变量和全局变量

作者头像
马克java社区
修改2019-10-08 12:13:12
5170
修改2019-10-08 12:13:12
举报
文章被收录于专栏:java大数据java大数据

2)局部变量和全局变量 浏览器里面 window 就是 global,通常可以省。 nodejs 里没有 window,但是有个叫 global 的。 例 3.2.1 <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <script> /* 有var无var, 在function外是一样的,都是全局的,在function里面时,var是局部的,而无var时是代表全局的*/ var testVar = "全量"; document.writeln("window.testVar is" + window.testVar+testVar); var testqVar = "全量q"; /*如不屏蔽下句话,程序直接停在这了,因为出错了,不认识testGlobal,得把下一句和下下句换一下位置,就ok了 */ // document.writeln("testGlobal is" + testGlobal); testGlobal = "全量global"; document.writeln("abc is" + abc); var abc; testGlobalInVar = "全量globalInVar"; function testSco() { var lll = "qqq"; var testVar = "局量"; //此testVar非外面的testVar testqVar = "全量qchange"; //此testqVar就是外面的testqVar testGlobal = "全量globalchange"; var testGlobalInVar = "局量global";//此testGlobalInVar非外面的testGlobalInVar /*local variable is stronger than global variable.so "testVar" in the following statement means local variable.*/ document.writeln(testVar); document.writeln(testqVar); document.writeln("testGlobalInVar is " + testGlobalInVar); } testSco(); document.writeln("second test is " + testVar); document.writeln("second testqVar is " + testqVar); document.writeln("testGlobal is " + testGlobal); document.writeln("testGlobalInVar is " + testGlobalInVar); </script>

更多请见:https://blog.csdn.net/qq_44594249/article/details/99864142

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档