1.6 KiB
1.6 KiB
id, challengeType, videoUrl, forumTopicId, title
id | challengeType | videoUrl | forumTopicId | title |
---|---|---|---|---|
56533eb9ac21ba0edf2244c0 | 1 | https://scrimba.com/c/c2QwKH2 | 18194 | 函数中的全局作用域和局部作用域 |
Description
局部
变量将会优先于全局
变量。
下面为例:
var someVar = "Hat";
function myFun() {
var someVar = "Head";
return someVar;
}
函数myFun
将会返回"Head"
,因为局部变量
优先级更高。
Instructions
myOutfit
添加一个局部变量来覆盖outerWear
的值为"sweater"
。
Tests
tests:
- text: 不要修改全局变量<code>outerWear</code>的值。
testString: assert(outerWear === "T-Shirt");
- text: <code>myOutfit</code>应该返回<code>"sweater"</code>。
testString: assert(myOutfit() === "sweater");
- text: 不要修改<code>return</code>语句。
testString: assert(/return outerWear/.test(code));
Challenge Seed
// Setup
var outerWear = "T-Shirt";
function myOutfit() {
// Only change code below this line
// Only change code above this line
return outerWear;
}
myOutfit();
Solution
var outerWear = "T-Shirt";
function myOutfit() {
var outerWear = "sweater";
return outerWear;
}