Check whether it's safe to iterate over a JavaScript variable
<p>I have a JavaScript function where someone can pass anything in, and I iterate over each of its keys using the</p>

<pre><code>for x in obj
</code></pre>

<p>syntax. However, this results in an error if they pass a primitive (string or number); the correct behavior is for the function to act the same way on those as it would on an object with no keys.</p>

<p>I can do a <code>try..catch</code> block to get around this, but is there another (more succinct) way?</p>
