Global vs. Local Scope in Functions

This commit is contained in:
Abhisek Pattnaik
2015-12-26 06:59:21 +05:30
committed by SaintPeter
parent 81e965b92a
commit 314fc1a75a

View File

@ -2024,9 +2024,9 @@
"id": "56533eb9ac21ba0edf2244c0",
"title": "Global vs. Local Scope in Functions",
"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:",
"<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.",
"<h4>Instructions</h4>",
"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() {",
" // Only change code below this line",
"",
"",
"",
" ",
" ",
" ",
" // Only change code above this line",
" return outerWear;",
"}",