Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That developer was wrong. Those two <em>myvar</em> are different. The outside one is equivalent to window.myvar, but the inside one is only inside the <em>f</em>.</p> <p>Edit: a very simple example: <a href="http://jsfiddle.net/mRkX3/" rel="nofollow">http://jsfiddle.net/mRkX3/</a></p> <p>Edit 2:</p> <p>A quote from the ECMAScript standard:</p> <blockquote> <p>If the variable statement occurs inside a FunctionDeclaration, the variables are defined with function-local scope in that function, as described in section 10.1.3. Otherwise, they are defined with global scope (that is, they are created as members of the global object, as described in section 10.1.3) using property attributes { DontDelete }. Variables are created when the execution scope is entered. A Block does not define a new execution scope. Only Program and FunctionDeclaration produce a new scope. Variables are initialised to undefined when created. A variable with an Initialiser is assigned the value of its AssignmentExpression when the VariableStatement is executed, not when the variable is created.</p> </blockquote> <p>Found through <a href="http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting" rel="nofollow">http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting</a> though that article is referencing a deadlink (live link: <a href="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf" rel="nofollow">http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf</a>).</p>
    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.
    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