This question (or similar) seems to get asked often, but I've tried many ways to check if the value returned from a function I have, is null or not; to no avail.
My function, get's URL parameters by name:
function getURLParameter(name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
);
}
However, obviously a parameter may not be there, so I need to do a check on the value returned.
Doing console.log( getURLParameter('client') );
returns null
...but doing null checks does not work.
I have tried the following:
if ( getURLParameter("client") !== null ) {
alert("It's there matey!");
}
if ( getURLParameter("client") != null ) {
alert("It's there matey!");
}
if ( ! getURLParameter("client") ) {
alert("It's there matey!");
}
None of these seems to work for me.
Is there anywhere I am going wrong? I can do this either in vanilla JS, or using jQuery library.