Simplest way of choosing a preferred variable value
<p>I have 3 variables, that are not always set. <code>o1</code>, <code>o2</code>, <code>o3</code>.</p>

<p>I want to create a new variable as follows:</p>

<p>if none are set: <code>o4 = null</code></p>

<p>if <code>o1</code> is set, <code>o4 = o1</code>, regarded of what the other are.</p>

<p>when <code>o1</code> is not set and <code>o2</code> is set: <code>o4 = o2</code></p>

<p>So <code>o4 = o3</code> only gets set when 1 and 2 are not set.</p>

<p>==</p>

<p>I am now using a long switch, but I bet it can be done better.</p>

<p>JavaScript / jQuery</p>

<pre><code>    var tmpl = '';

    if(data.o3 != null)
        tmpl = data.o3;

    if(data.o2 != null)
        tmpl = data.o2;

    if(data.o1 != null)
        tmpl = data.o1;
</code></pre>
