-1

avoidP2P() || t < lowBuffer || 0 === a.size(p2pManager.swarm.utils.contributors) ? requestToCDN() : requestToP2P()

If the above functions are as follows: A || B || C

Does C run?

sujkh85
  • 109
  • 8

2 Answers2

0

It means "Get the first value from these that is not falsy", being "falsy" some of:

false
null
undefined
0
NaN
''

More info here: https://developer.mozilla.org/en-US/docs/Glossary/Falsy

franciscod
  • 992
  • 4
  • 17
0

In JavaScript, the || operator means "or". So for a function like A || B || C:

1. JavaScript will first try to evaluate the value of A, if it is true, the execution will stop and B and C won't even get called.

2. However, if A evaluates falsy, then JS will execute B. In the same manner, if B returns true, then execution is stopped and C won't get called.

3. Only and only if both A and B evaluates false, then JS will try C hoping to get a true value.

For your reference, falsy values are:

null
false
0
undefined
''
[]
{}

Hope that helps!

Abraar Arique Diganto
  • 1,215
  • 16
  • 24
  • @sujkh85 No problem. If my answer helps you, please accept the answer by clicking the green checked button on the left. Happy coding! – Abraar Arique Diganto Jul 15 '15 at 06:45
  • 1
    To be precise, `A` is not "run" and does not "return" anything. It is "evaluated" to some "value". Also, for clarity, it's probably better to use "falsy" instead of "false". `false` has a very specific meaning as a boolean value. –  Jul 15 '15 at 06:46
  • @torazaburo You have a point, I'll try to fix the answer. – Abraar Arique Diganto Jul 15 '15 at 06:48