Prevent getting error if variable is undefined?
<p>I need to replace imagesrc with the value stored in this object. However when I run:</p>

<pre><code>if(data['results'][res]['entities']['media']["0"]["media_url"]) {
    imagesrc = data['results'][res]['entities']['media']["0"]["media_url"];
}
</code></pre>

<p>I get the error:</p>

<pre><code>Cannot read property '0' of undefined
</code></pre>

<p>How can I run my condition so that I don't get errors if something is undefined?</p>
