Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>var</code> declarations affect the entire scope of the smallest containing function or program. JavaScript is not block scoped.</p> <p><a href="http://javascript.crockford.com/code.html" rel="nofollow">Crock</a> says:</p> <blockquote> <p><strong>Variable Declarations</strong></p> <p>All variables should be declared before used. JavaScript does not require this, but doing so makes the program easier to read and makes it easier to detect undeclared variables that may become implied globals. Implied global variables should never be used.</p> <p>The <code>var</code> statements should be the first statements in the function body.</p> <p>It is preferred that each variable be given its own line and comment. They should be listed in alphabetical order.</p> <pre><code>var currentEntry; // currently selected table entry var level; // indentation level var size; // size of table </code></pre> <p>JavaScript does not have block scope, so defining variables in blocks can confuse programmers who are experienced with other C family languages. Define all variables at the top of the function.</p> <p>Use of global variables should be minimized. Implied global variables should never be used.</p> </blockquote> <p>Note, this is changing with the <a href="http://wiki.ecmascript.org/doku.php?id=harmony%3ablock_scoped_bindings" rel="nofollow"><code>let</code> statement</a>, and in current JavaScript (EcmaScript 5), the variable name in a <code>catch</code> block is block scoped.</p>
 

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