javascript variable's scope , 变量 范围

本文深入探讨了Python中变量的作用域,包括局部变量、全局变量及它们的使用方式。详细介绍了如何在不同作用域内引用变量,并通过具体实例展示了如何在函数内部声明和使用局部变量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Detailed example that writes to this page: 

You can reference all local variables inside the same function the variables are declared.

(L1) local variable declared with var keyword

(L2) local variable declared without var keyword

(L3) local variable declared with var keyword inside if statement

 

You can reference all global variables inside any function.

(G1) global variable declared with var keyword

(G2) global variable without var keyword

(G3) global variable declared with var keyword inside if statement

 

Outside a function, you can only reference local variables that are not declared with the var keyword.

Commented out. Cannot reference (L1)

(L2) local variable declared without var keyword

Commented out. Cannot reference (L3)

 

Outside a function, you can reference all global variables.

(G1) global variable declared with var keyword

(G2) global variable without var keyword

(G3) global variable declared with var keyword inside if statement

转载于:https://my.oschina.net/xiaohelong/blog/366849

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值