 <p>Whoever first wrote that code was either</p> <p>a) Being very defensive against future use. b) Didn't understand how <code>attr</code> works.</p> <p>The method <code>attr</code> (or the underlying call of <code>getAttribute</code> will return either</p> <ul> <li>A string value, of the attribute is found</li> <li><code>null</code>, if it is not.</li> </ul> <p>Importantly, should there have been a <code>0</code> value, it would be a <em>string</em> <code>0</code>, <strike>and thus not caught in the test below</strike> -- caught against the <code>price == 0</code> test because the system would have automatically converted it to a number as part of the <code>==</code> compare.</p> <pre><code>if(price=="" || price==0 || price==null || price==undefined ) </code></pre> <p>And, due to the way that conversions work internally, those tests don't work as intended. <code>==</code> and <code>===</code> are different. It should be:</p> <pre><code>if(price === "" || price === 0 || price === null || price === undefined ) </code></pre> <p>All of which can easily be reduced to simply "price" due how how <a href="http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/" rel="nofollow">coercion to boolean work</a>:</p> <pre><code>if (!price) </code></pre> <p>Or, if you want to catch <code>"0"</code> values</p> <pre><code>if (!price || +price === 0) </code></pre> <p>(the +price forces price to be a number, so we catch <code>0</code> <code>0.00</code> and other variations.)</p>