Q:

jquery get url param if exists

Im trying to construct a script that will check if a url variable called result exists and if it does then it checks if the value equals success or not.
I tried the following but if result doesn't exist then it errors my script as undefined
function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}
var first = getUrlVars()["result"];
alert(first);

A:

And why don't you simply check if it is undefined ? 
if (first !== undefined)
     alert(first);
else alert('ooops');

Or you probably can also define something like a 'default value': 
var first = getUrlVars().result || '';

