0

Possible Duplicate:
What does this construct mean?

I'm encountering this syntax for the first time and am not sure what it's doing:

self.name = _searchString(settings.dataBrowser) || "An unknown browser";

What does the or (double pipes) condition do? When would self.name be set to the second value?

Community
  • 1
  • 1
Paul Erdos
  • 1,355
  • 2
  • 23
  • 47

3 Answers3

6

This is the logical or operator.

It evaluates to its first "truthy" operand.

In particular, it will evaluate to the second operand if the first operand is "falsy" — null, false, undefined, 0, "", or NaN.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

Crockford calls / called it a default operator

Allen Rice
  • 19,068
  • 14
  • 83
  • 115
0

this is directly related to a question i have asked, you can read about it here Short-circuit evaluation via the AND operator in PHP

so basically, it sets self.name to the value returned from the function, but if the function returns false, it sets itself to "An unknown browser";

Community
  • 1
  • 1
Jan Dragsbaek
  • 8,078
  • 2
  • 26
  • 46