I've watched several Doug Crockford videos about the "right" way to do JavaScript and I've tried to follow his suggestions. Currently in our system we do lot of
if (myvar != null) {
//do some stuff
}
However, I understand this only works because of type coercion and that myvar is actually undefined until it is initialized.
I have a common block of code in which I've added some new stuff that I only want executed one one page. In that one page's JavaScript I've put a new variable ala:
var doingStuffTheNewWay = true;
In my common block of code I have a test like:
if (doingStuffTheNewWay && someOtherCondition) {
// new code
} else {
// old code
}
However, it's blowing up on evaluating doingStuffTheNewWay and not going into my else case. I thought it would evaluate doingStuffTheNewWay as a falsie value, if it didn't know what it was ala Is there a standard function to check for null, undefined, or blank variables in JavaScript?. Any suggestions for how to handle this?