title: How can I check a image URL with JavaScript?
body: <p>So I am trying to check if an image URL is valid or not, in which it has to return a <code>true</code> or <code>false</code> value. The problem is that I can't figure out how to achieve this. I'm using ionic 4.0 and this is what I already have:</p>
  
  <pre><code>imageExists(url, callback) {
     const img = new Image();
     img.onload = function () { callback(true); };
     img.onerror = function () { callback(false); };
     if(callback === true ) {
       return true;
      } else {
        return false;
      }
  }
  
    const imageUrl = 'https://www.google.com/images/srpr/nav_logo14.png';
    let bool = this.imageExists(imageUrl, function (exists) {
      console.log('RESULT: url=' + imageUrl + ', exists=' + exists);
      console.log(exists);
      bool = exists;
    });
  
  
  console.log(bool);
  </code></pre>