If your Drupal installation isn't in the root of the website (i.e. the Drupal site is at example.com/drupal), then you can set the base URL in the settings file so that links in templates will point to the right place.

You can also access the base URL in a Javascript file (again, if you need to add a link) by using Drupal.settings.basePath.

Example:

var baseUrl = Drupal.settings.basePath;
console.log(baseUrl); // will be '/' if base URL isn't set