var current_url = location.href;
Here is another way:-
var current_url = document.URL;
Suppose, you have query string in your URL and you only want to get the actual URL without the query string.
Here is the code for this:-
var url = location.href;
var url_parts = url.split(‘?’);
var main_url = url_parts;
Hope this helps. Thanks.