Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>assuming that the parsing goes from top to bottom, setSquare isnt defined yet so shouldn't it return an error?</p> </blockquote> <p>Function declarations are <em>hoisted to the top</em> of the containing scope. <code>function setSquare() {}</code> is a function declaration, so your code is effectively the same as declaring the function before the loop:</p> <pre><code>function setSquare (thisSquare) { //... } for(var i=0; i&lt;24; i++){ setSquare( i ) } </code></pre> <blockquote> <p>how does javascript know that "square" in function 2 is a id and not a string?</p> </blockquote> <p>It does not. It is a string and is treated as such. There is nothing like an "id datatype" in JavaScript. <code>currSquare</code> is a variable containing the string <code>"squareX"</code> where X is the value from <code>thisSquare</code> (0 to 23).</p> <blockquote> <p>there IS no ID on main page of <code>currSquare</code> so how can it "get" it</p> </blockquote> <p><code>document.getElementById</code> expects a string as argument. This string should be an id of some element. There is nothing special about this. Instead of passing a literal string, you are passing the one contained in <code>currSquare</code> (just like you pass the integer contained in <code>i</code> to <code>setSquare</code>).</p> <hr> <p>It seems you have not fully understood the basics yet, although your are doing a tutorial. Maybe the <a href="https://developer.mozilla.org/en/JavaScript/Guide" rel="nofollow"><em>MDC JavaScript Guide</em></a> will help you more. Read especially about <a href="https://developer.mozilla.org/en/JavaScript/Guide/Values,_Variables,_and_Literals" rel="nofollow"><em>Values, Variables, and Literals</em></a> and <a href="https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope" rel="nofollow"><em>Functions and function scope</em></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. 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.
 

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