Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't, because the variable of the outer scope <em>is shadowed</em> by the one on your inner function.</p> <p>The scope chain on the <code>innerFunction</code> looks something like this:</p> <pre> innerFunction outerFunction global object ______________________ ________________________ _______________ |* someString = 'Hello'| &lt;---- | someString = 'Hai!' | &lt;---|* outerFunction| ---------------------- |* content = [HTMLElement]| | ..... | |* someNum (argument) | --------------- |* innerFunction | ------------------------- <b>*</b> Denotes a resolvable identifier from the scope of <b>innerFunction</b>. </pre> <p>Each function has its own <em>Variable Object</em>, is where the identifiers of Function Declarations, Variable Declarations, and function Formal Parameters live, as properties.</p> <p>Those objects are not directly accessible by code, the scope chain is formed by all those chained objects.</p> <p>When an identifier is <a href="http://bclary.com/2004/11/07/#a-10.1.4" rel="nofollow noreferrer">resolved</a>, the lookup goes up in the scope chain, looking for the first appearance of it, until the global object is reached, if the identifier is not found, a <code>ReferenceError</code> is thrown.</p> <p>Give a look to the following articles:</p> <ul> <li><a href="http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/" rel="nofollow noreferrer">ECMA262-3 in detail: The Variable Object</a></li> <li><a href="http://javascriptweblog.wordpress.com/2010/08/09/variables-vs-properties-in-javascript/" rel="nofollow noreferrer">Variables vs. Properties in JavaScript</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload