title: Javascript difference between eval() and appending script tags
body: <p>I was wondering if someone could explain the difference between using Javascript's eval(), and another approach, like using JQuery to create script tags and then appending that element to the page:</p>
  
  <pre><code>eval(somecode);
  </code></pre>
  
  <p>vs.</p>
  
  <pre><code>$("&lt;script type='text/javascript'&gt;"+somecode+"&lt;/script&gt;").appendTo("head");
  </code></pre>
  
  <p>Not sure if this is relevant, but here's the context: I'm working with a version of the Drupal Popups module whose basic purpose is to easily turn regular links into popups by AJAX'ing an entire page request and appending it to the page in a modal window. This frequently includes external CSS and Javascript files. In an effort to improve the performance of all this AJAX loading I switched over to use AJAX queueing, and I changed an eval() of external scripts into the alternative listed about. However, that caused sporadic Javscript bugs on various other pages.</p>