--- id: 56533eb9ac21ba0edf2244c0 title: Global vs. Local Scope in Functions challengeType: 1 videoUrl: '' localeTitle: 功能中的全局与局部范围 --- ## Description
可以使本地变量和全局变量具有相同的名称。执行此操作时, local变量优先于global变量。在这个例子中:
var someVar =“帽子”;
function myFun(){
var someVar =“Head”;
返回someVar;
}
函数myFun将返回"Head"因为存在变量的local版本。
## Instructions
将一个局部变量添加到myOutfit函数,以使用"sweater"覆盖outerWear的值。
## Tests
```yml tests: - text: 不要更改全局outerWear的值 testString: assert(outerWear === "T-Shirt"); - text: myOutfit应该返回"sweater" testString: assert(myOutfit() === "sweater"); - text: 不要更改return语句 testString: assert(/return outerWear/.test(code)); ```
## Challenge Seed
```js // Setup var outerWear = "T-Shirt"; function myOutfit() { // Only change code below this line // Only change code above this line return outerWear; } myOutfit(); ```
## Solution
```js // solution required ```