JavaScript Best Practices
<p>This is somewhat related to <a href="http://stackoverflow.com/questions/39691/javascript-best-practices">this question</a>, but I'm not asking for resources about best practices in JavaScript, but your actual advise.</p>

<p>I'll start with my own list. You may either post an answer or directly edit the question if you're sure the advise is not controversial.</p>

<p>Here we go:</p>

<ul>
<li>always use <code>var</code></li>
<li>capitalize names of constructor functions - and nothing else</li>
<li>use <code>===</code> for comparison</li>
<li>use explicit casts for primitives, e.g. <code>Number()</code>, <code>String()</code>, <code>Boolean()</code></li>
<li>check for primitive types with <code>typeof</code></li>
<li>check for object types with <code>instanceof</code></li>
<li><p>check for built-in object types with <code>Object.prototype.toString()</code> to avoid cross-frame issues, e.g.</p>

<pre><code>Object.prototype.toString.call(obj) === '[object Array]'
</code></pre></li>
<li><p>check <code>this</code> in constructors, e.g.</p>

<pre><code>function MyObject() {
    if(!(this instanceof arguments.callee))
        throw new Error('constructor called with invalid `this`');
    // [...]
}
</code></pre></li>
<li><p>use anonymous functions for namespacing to not pollute the global scope, e.g.</p>

<pre><code>(function() {
    var noGlobalVar = 'foo';
    // [...]
})();
</code></pre></li>
<li><p>check <code>hasOwnProperty()</code> in <code>for..in</code> loops - don't assume that no one messed with the prototypes</p></li>
<li>don't use <code>for..in</code> loops to iterate over elements of arrays or array-like objects</li>
</ul>
