![](/img/trans.png)
[英]What happens when JavaScript variable name and function name is the same?
[英]What happens if a function takes a parameter that overlaps with a global (same name) variable?
另一個 javascript 101 問題,但這里是:
var iamglobal='yep, im global';
function test(iamglobal){
...
}
test('overlapage boh!');
在這種情況下,iamglobal 會發生什么?
全局iamglobal
變量被局部iamglobal
變量遮蔽。
它們彼此獨立存在,但不能從函數作用域到達全局,使用iamglobal
標識符時只會影響局部變量。
沒有。 函數體只是失去了引用全局變量的能力,因為參數的名稱隱藏了它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.