I have this statement:
pn = r.notFound == "true" ? "Not currently assigned" : "Currently assigned to VPMO " + r.currentAssignment;
and I need to add a condition for "undefined" and then a value to it. It basically needs to read something like…
r.notFound == "undefined开发者_开发问答" then “Already assigned to this project”
else if
r.notFound == “true” then “Not currently assigned”
else
“Currently assigned to VPMO “ + r.currentAssignment;
var pn;
if (r.notFound == 'undefined') { // be aware that this checks for STRING undefined
pn = 'Already assigned to this project';
} else if (r.notFound == 'true') { // be aware that this checks for STRING true
pn = 'Not currently assigned';
} else {
pn = 'Currently assigned to VPMO ' + r.currentAssignment;
}
?
EDIT
If you want to check whether the variable is defined use:
if (typeof r.notFound === 'undefined')
you can use multiple nested ternary operator:
r.notFound == "undefined" ?
"Already assigned to this project" :
(r.notFound == "true" ? "Not currently assigned" : "Currently assigned to VPMO " + r.currentAssignment)
精彩评论