title: Calling a JavaScript function in another js file
body: <p>I wanted to call a function defined in a <em>first.js</em> file in <em>second.js</em> file. Both files are defined in an HTML file like:</p>
  <pre><code>&lt;script type=&quot;text/javascript&quot; src=&quot;first.js&quot;&gt;&lt;/script&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;second.js&quot;&gt;&lt;/script&gt;
  </code></pre>
  <p>I want to call <code>fn1()</code> defined in <code>first.js</code> in <code>second.js</code>. From my searches answers were if <code>first.js</code> is defined first it is possible, but from my tests I haven't found any way to do that.</p>
  <p>Here is my code:</p>
  <p><code>second.js</code></p>
  <pre><code>document.getElementById(&quot;btn&quot;).onclick = function() {
      fn1();
  }
  </code></pre>
  <p><code>first.js</code></p>
  <pre><code>function fn1() {
      alert(&quot;external fn clicked&quot;);
  }
  </code></pre>