Idiomatic way to set default value in javascript
<p>What would be the most idiomatic way to do the following in javascript:</p>

<p>If myParam is not passed into MyFunc by the caller, then I want to set it to a default value.  But first I want to try and get it from another object, which may not yet exist: </p>

<pre><code>function MyFunc(myParam) {

    if (!myParam) {
        if (!myObj) {
            myParam = 10;
        }
        else {
            myParam = myObj.myParam;
        }
    }

    alert(myParam);
}
</code></pre>

<p>I started to write:</p>

<pre><code>    myParam = myParam || myObj.mParam || 10
</code></pre>

<p>but realized that if myObj does not exist then this would fail.  I might guess the following:</p>

<pre><code>    myParam = myParam || (myObj &amp;&amp; myObj.mParam) || 10
</code></pre>

<p>It might even work.  But is it the best way?</p>

<p>How would for example John Resig do it?</p>
