title: javascript assign variable value when script.onerror occurs
body: <p>I am trying to assign variable value within script.onerror = function(){  }</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function CheckScriptThenDoSomething (){
  
    var VariableA;
  
    let script = document.createElement('script');
    script.src = "../Dummy.js";
    document.head.append(script);
    script.onerror = function () {
          location.href = '#ABC';
          VariableA = true;
    };
    
    //The problem is, at outside of the script.onerror, The VariableA  value is lost, I cannot use the value of VariableA to do something,
    if(VariableA == true){
      //The code written here never runs, the value of VariableA is null,
    }
    
   }</code></pre>
  </div>
  </div>
  </p>
  <p>When script error occurs (eg. if script hasn't been found), location.href = '#ABC'; works fine but variable assignment: VariableA = true; never happens. I mean I cannot use the value of VariableA to do something outside of script.onerror = function () { } code block.</p>
  <p>Can someone show me how to assign variable value inside script.onerror = function () { ... }?</p>
  <p>Also, is there anything like script.onsuccess ?</p>
  <p>Thank you,</p>