Testing if JS Variable is set as a function parameter
<p>What is the best way to test if a javascript variable is passed a value into a function</p>

<pre><code>function test(a, b) {  /* check if b was given a value */ }
</code></pre>

<p>I want to say</p>

<pre><code>if(!b)
</code></pre>

<p>but this doesn't work if <code>b = 0</code>. Do I have to individually check if it is undefined or null like</p>

<pre><code>if(typeof(b) === 'undefined' || b === null)
</code></pre>

<p>or is there a better way to write this?</p>
