Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What's wrong with writing it as follows:</p> <pre><code>if (x === 0) { // you should always use === over == in JavaScript for (var i = 0; i &lt; 10; i++) { // body } } </code></pre> <p>Just because JavaScript doesn't support block scoping doesn't mean that you can't declare variables in block scopes.</p> <p><strong>You can declare variables anywhere.</strong> However they'll be visible everywhere in the scope of the function.</p> <p>The only problem caused by the lack of block scoping in JavaScript is when you define a function inside a loop which accesses free variables (the infamous loop problem).</p> <p>Read the following StackOverflow thread to wrap your head around it: <a href="https://stackoverflow.com/q/750486/783743">JavaScript closure inside loops – simple practical example</a></p> <p>JavaScript is simple. <strong>Way more simple than C or Java.</strong> It's a lot more sensible than Java too. Java is a pathetic language.</p> <p>If you want the JavaScript community to be daggers against you then you're doing a wonderful job. Otherwise just <a href="http://www.embracejs.com/" rel="nofollow noreferrer" title="Embrace">embrace JavaScript</a>. In the words of Douglas Crockford:</p> <blockquote> <p>In my own practice, I have found that working with JavaScript has made me a better Java programmer because it introduced me to a useful set of dynamic techniques.</p> </blockquote> <p>Source: <a href="http://www.crockford.com/javascript/survey.html" rel="nofollow noreferrer" title="JavaScript: A Survey of the Language">A Survey of the JavaScript Programming Language</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