Why am I finding Javascript/jQuery so difficult to get right?
<p>My background is in C and I've picked up PHP, mySQL, HTML, CSS without too much issue.</p>

<p>But I'm finding Javascript/jQuery surprisingly difficult to get right.
Very frustrating.
Why?</p>

<ol>
<li><p>It seems to violate a number of traditional programming principles (e.g. variable scope) </p></li>
<li><p>Undefined variables seem to appear out of nowhere and already have values associated with them. For example (from the jQuery docs): </p>

<pre><code>$("a").click(function(event) {
    event.preventDefault();
    $('&lt;div/&gt;')
          .append('default ' + event.type + ' prevented')
          .appendTo('#log');
});
</code></pre>

<p>What exactly is "event"? Do I have to use this variable name? Should I just assume that this object is magically instantiated with the right stuff and I can use any of the methods list at the <a href="http://api.jquery.com/category/events/">JQuery API</a>?</p></li>
<li><p>There seems to be bunch of random rules (e.g. return false to stop a default action, but sometimes this doesn't work?) </p></li>
<li><p>Non-deterministic behavior when debugging. (e.g. I refresh the browser, try something and get result X for JS variables I'm watching in Firebug.  I refresh again and I get result Y?)</p></li>
<li><p>Very messy looking code that is hard to follow. What happens when? I'm using Firebug and Chrome Developer Tools, but I'm not getting enough visibility.</p></li>
</ol>

<p>It seems like everyday there's some random JS "rule" that comes up that I've never seen before in any of my JS books or tutorials.  </p>

<p>What do I need to do to make Javascript/jQuery more deterministic, controlled, and logical to me?</p>

<p>Are there any resources that explain Javascript's quirks/gotchas?</p>

<p>Thanks!</p>
