How is JavaScript included in Drupal 7?
if scripts[] variable additions are added before drupal_add_js() calls, etc


The JavaScript files used by a theme, and defined with scripts[] directives are added in _drupal_theme_initialize(), using the following code.

  // Do basically the same as the above for scripts
  $final_scripts = array();

  // Grab scripts from base theme
  foreach ($base_theme as $base) {
    if (!empty($base-&gt;scripts)) {
      foreach ($base-&gt;scripts as $name =&gt; $script) {
        $final_scripts[$name] = $script;
      }
    }
  }

  // Add scripts used by this theme.
  if (!empty($theme-&gt;scripts)) {
    foreach ($theme-&gt;scripts as $name =&gt; $script) {
      $final_scripts[$name] = $script;
    }
  }

  // Add scripts used by this theme.
  foreach ($final_scripts as $script) {
    drupal_add_js($script, array('group' =&gt; JS_THEME, 'every_page' =&gt; TRUE));
  }


_drupal_theme_initialize() is indirectly called from theme(), l(), contextual_preprocess(), and ThemeRegistry::initializeRegistry(). 

As each JavaScript file added to a page has its own group, with its own weight, it doesn't generally have importance which file is added first. If you really need to be sure a file is included before another one, you should define its group, and its weight, consider that files are included following this order:


First by scope, with 'header' first, 'footer' last, and any other scopes provided by a custom theme coming in between, as determined by the theme
Then by group
Then by the 'every_page' flag, with TRUE coming before FALSE
Then by weight
Then by the order in which the JavaScript was added