I wasn't sure how to properly word the title for this question but jumping right into it,
Using the the ? : operator I setup a JavaScript variable and an if statement like so:
var test = callsAFunction ? test : false;
if I do this, will test equal whatever the function returns here? Or will it be undefined since it's "Technically" not set yet?
What I'm trying to do is set a variable to either what data it gets back and is run through a function, or set it to Boolean false so it will process through my Boolean check as an error. I figured this approach was best but I'm running into issues determining how to go about this. Below are my code snippets:
var hash = self.getHashFromMasterRecords(d[0]);
if(hash === false){
done("Can't find master record hash", self.requestData, self);
}
Obviously it needs to turn false as a Boolean in order to pass as an error. I want to do this without having to call the function more than 1 time for this sequence.
So if I do var hash = self.getHashFromMasterRecords(d[0]) ? hash : flase; would hash return the value? Or undefined?
Thank you ahead of time, if I need to post more info let me know.
var hash = self.getHashFromMasterRecords(d[0]) || false;is probably what you are looking for