If variable exists.....object vs variable, null vs. undefined
The first part of this script seems to work correctly, it iterates through every document and if the document name matches a particular regex pattern, it it gives it a specific variable to be utilized later in the script.
However, in line 37 of the script when I attempt to us whether or not a variable exists as a condition for an if statement, things don't evaluate true or false as expected.
What am I doing wrong here?
// iterate through all docs assigning variables to templates and art
for (i = 0; i < documents.length; i++){
var curDoc = app.activeDocument = app.documents;
var curDocNoExt = curDoc.name.split(".");
var workingName = curDocNoExt[0];
if(workingName.match(/^\d{5,6}$/) != null) {
var frontArt = app.documents;
var targetName = frontArt.name
} else {
if(workingName.match(/^\d{5,6}(b))$/) != null) {
var backArt = app.documents;
var backToggle = 1;
} else {
if(workingName.match(/^fkeep$/) != null) {
var frontTemp = app.documents;
} else {
if(workingName.match(/^fxkeep$/) != null) {
var frontSquare = app.documents;
} else {
if(workingName.match(/^bkeep$/) != null) {
var backTemp = app.documents;
} else {
if(workingName.match(/^bxkeep$/) != null) {
var backSquare = app.documents;
}
}
}
}
}
}
}
//use variables to do stuff!
if (backArt != null) {
app.activeDocument = backTemp;
var namedBackTemp = backTemp.duplicate(targetName + "B");
}
I have also this on line 37, but they didn't seem to fix things:
if (backArt != 'undefined') {
