JS check if img is not found
<p>So, I have following js img var.</p>

<pre><code>//Where `img_src` is another variable which actual image file MIGHT or MIGHT NOT exist.
var img_source = "/images/" + img_src;   
return '&lt;img  src="' + img_source + '"&gt;';    
</code></pre>

<p>Because <code>img_src</code> might or might not be available, sometimes I am getting <code>404 Not Found</code> error.</p>

<p>If there is no image, then I want to perform another function.</p>

<p>How do I check if the image file is available in this case?</p>

<p>I am trying to avoid showing the img attribute all together if image is not available. Thanks!</p>