Elizabeth "Smalls" Eckels
asked on
How do the JavaScript && !== operators work together?
function() {
return '{{visitor.id}}' && '{{visitor.id}}' !== 'undefined' ? '{{visitor.id}}' : undefined;
}
Hi - I'm trying to debug some code and don't know JavaScript well enough to fully understand this piece of code. But from what I can gather, I believe this piece of code says (in laymens terms)
Return visitor.id if visitor.id is undefined
Is this correct? If not, could you help me understand what this is doing?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You are welcome.
ASKER
The context of the expression was to prevent an analytics system from overwriting a Visitor ID (such as ABC123) with "false" or "undefined" on web pages where it was false or undefined. The analytics system itself can't be configured to ignore undefined or false values, so that was the intent of this expression. I just didn't understand if, how or why it worked...but now I do. Thanks Julian!