Global vs. Local Scope in Functions
This commit is contained in:
committed by
SaintPeter
parent
81e965b92a
commit
314fc1a75a
@ -2026,7 +2026,7 @@
|
|||||||
"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>."
|
||||||
|
Reference in New Issue
Block a user