* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
1.8 KiB
1.8 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244bf | Local Scope and Functions | 1 | https://scrimba.com/c/cd62NhM | 18227 | local-scope-and-functions |
--description--
Variables which are declared within a function, as well as the function parameters have local scope. That means, they are only visible within that function.
Here is a function myTest
with a local variable called loc
.
function myTest() {
var loc = "foo";
console.log(loc);
}
myTest(); // logs "foo"
console.log(loc); // loc is not defined
loc
is not defined outside of the function.
--instructions--
The editor has two console.log
s to help you see what is happening. Check the console as you code to see how it changes. Declare a local variable myVar
inside myLocalScope
and run the tests.
Note: The console will still have 'ReferenceError: myVar is not defined', but this will not cause the tests to fail.
--hints--
The code should not contain a global myVar
variable.
function declared() {
myVar;
}
assert.throws(declared, ReferenceError);
You should add a local myVar
variable.
assert(
/functionmyLocalScope\(\)\{.+(var|let|const)myVar[\s\S]*}/.test(
__helpers.removeWhiteSpace(code)
)
);
--seed--
--seed-contents--
function myLocalScope() {
// Only change code below this line
console.log('inside myLocalScope', myVar);
}
myLocalScope();
// Run and check the console
// myVar is not defined outside of myLocalScope
console.log('outside myLocalScope', myVar);
--solutions--
function myLocalScope() {
// Only change code below this line
var myVar;
console.log('inside myLocalScope', myVar);
}
myLocalScope();
// Run and check the console
// myVar is not defined outside of myLocalScope
console.log('outside myLocalScope', myVar);