I’ve always found that it is easier to drop the query string into an object similar to the $_GET object in PHP. This allows you to grab any query variable by it’s name by simply calling window.query.name or window.query['name'] as well as getting the number of query vars available via window.query.length to simply check if any exist.  For the hash, I like to use it as a breadcrumb style path separated by slashes, so here I’ve split it into an array that can be accessed via window.hash[2] and accurately report the number of parts with window.hash.length that reports an empty ‘#’ as 0.

// Query | Hash Globals
window.query = new Object();
window.hash = new Array();

// Populate Query String Object, iterate over each name-value pair
window.query.length = 0;
window.location.search.replace(
	new RegExp('([^?=&]+)=([^&]*)?', 'g'),
	// populate the object with the values by name
	function($0, $1, $2) { window.query[$1] = $2; window.query.length++; }
);

// Split the hash into sections by / or any other char
window.hash = window.location.hash.slice(1).split('/');
window.hash.length = window.hash.length == 1 && window.hash[0] == ''? 0: window.hash.length;