Link to home
Start Free TrialLog in
Avatar of Elizabeth "Smalls" Eckels
Elizabeth "Smalls" EckelsFlag for United States of America

asked on

How do the JavaScript && !== operators work together?

function() {
return '{{visitor.id}}' && '{{visitor.id}}' !== 'undefined' ? '{{visitor.id}}' : undefined;
}

Open in new window


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
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Elizabeth "Smalls" Eckels

ASKER

This was a very good explanation, thank you so much.

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!
You are welcome.