SharePoint current Site Collection or site URL in JavaScript

In Sandbox Solutions or Office 365, many times you need to get the URL of the current site to use in JavaScript.

With the ECMAScript Client Object Model, there are multiple ways to access the current site URL like SP.Site.get_url() for the Root site URL or SP.Web.get_serverRelativeUrl() for the relative url of the current site.

But for plain JavaScript code, there is an easier way to get the URL by using the OOB JavaScript variable L_Menu_BaseUrl which stores the URL of the current Web or the Subsite.

There are some more OOB Javascript variables which can be useful. 

L_Menu_LCID : This contains the LCID setting of the current site.

L_Menu_SiteTheme : This contains the theme name of the current site.

_spUserId : This contains the id of the current user.