Global vs. Local Scope in Functions
This commit is contained in:
committed by
SaintPeter
parent
81e965b92a
commit
314fc1a75a
@ -2024,9 +2024,9 @@
|
|||||||
"id": "56533eb9ac21ba0edf2244c0",
|
"id": "56533eb9ac21ba0edf2244c0",
|
||||||
"title": "Global vs. Local Scope in Functions",
|
"title": "Global vs. Local Scope in Functions",
|
||||||
"description": [
|
"description": [
|
||||||
"It is possible to have both a <dfn>local</dfn> and <dfn>global</dfn> variables with the same name. When you do this, the <code>local</code> variable takes precedence over the <code>global</code> variable.",
|
"It is possible to have both a <dfn>local</dfn> and <dfn>global</dfn> variables with the same name. When you do this, the <code>local</code> variable takes precedence over the <code>global</code> variable.",
|
||||||
"In this example:",
|
"In this example:",
|
||||||
"<blockquote>var someVar = \"Hat\";<br />function myFun() {<br /> var someVar = \"Head\";<br /> return someVar;<br />}</blockquote>",
|
"<blockquote>var someVar = \"Hat\";<br>function myFun() {<br> var someVar = \"Head\";<br> return someVar;<br />}</blockquote>",
|
||||||
"The function <code>myFun</code> will return <code>\"Head\"</code> because the <code>local</code> version of the variable is present.",
|
"The function <code>myFun</code> will return <code>\"Head\"</code> because the <code>local</code> version of the variable is present.",
|
||||||
"<h4>Instructions</h4>",
|
"<h4>Instructions</h4>",
|
||||||
"Add a local variable to <code>myFunction</code> to override the value of <code>outerWear</code> with <code>\"sweater\"</code>."
|
"Add a local variable to <code>myFunction</code> to override the value of <code>outerWear</code> with <code>\"sweater\"</code>."
|
||||||
@ -2043,9 +2043,9 @@
|
|||||||
"",
|
"",
|
||||||
"function myFunction() {",
|
"function myFunction() {",
|
||||||
" // Only change code below this line",
|
" // Only change code below this line",
|
||||||
"",
|
" ",
|
||||||
"",
|
" ",
|
||||||
"",
|
" ",
|
||||||
" // Only change code above this line",
|
" // Only change code above this line",
|
||||||
" return outerWear;",
|
" return outerWear;",
|
||||||
"}",
|
"}",
|
||||||
|
Reference in New Issue
Block a user