I have some JavaScript which is used to read and write cookies. As part of the scrip, I have to dismiss some ASPsession parts that are reported. There's some splitting going on and eventually I get to the parts I need.

However, if no cookie exists, one line of code reports that the value of something is undefined. I need to know how I can identify this scenario, and react accordingly.

I've tried:

if (strExistingCookie==undefined) {...}
if (strExistingCookie=="undefined") {...}
if (strExistingCookie.undefined==true) {...}
if (strExistingCookie.undefined) {...}
if (isObject(strExistingCookie)) {...}
if (isNull(strExistingCookie)) {...}
if (isEmpty(strExistingCookie)) {...}

And none of them work. I must be confusing VBscript with JavaScript and all sorts.

So, in a nutshell, how can I do this?!

function write_cookie(newItem) {
//get value of any existing cookie data held
read_cookie();
//make sure it's not empty
>>>> need something like 'if cookie is undefined then cookie' = "", otherwise it writes the value undefined in to the cookie
var expDate = new Date();
expDate.setTime (expDate.getTime() + 1000 * 60 * 60 * 24 * 365);
var strCookie = strExistingCookie + newItem + "; path=/; expires=" + expDate.toGMTString();
// alert ("WRITING this cookie value: " + strCookie);
document.cookie = strCookie;
}


Hope this is clear!

Look forward to your help, folks