Assuming your code looks like this:
return e.input || L(), e.addTest = function(a, b) {
...
}
This code will:
- Evaluate
e.input || L()
- This means that
L
will run if e.input
is not falsy (undefined
, 0
, false
, null
, empty string)
- Evaluate
e.addTest = function(a, b) { ... }
- This stores a new function in
e.addTest
- Then, yields that function for the whole expression, so that function is returned
You can think of this as:
return ( ( e.input || L() ), e.addTest = function() { ... } )
where the ||
operation is done first, followed by the assignment operation.
This is because:
- The
||
operator is short-circuting, and will yield its first non-falsy operand
- So
return a || b
returns a
if a
is truthy or otherwise returns b
- The
,
operator evaluates both operands to the left and right, but then yields the right operand
- So
return a(), b()
runs both a()
and b()
but returns the result of b()
- The assignment operation yields the value assigned
- So
return a = 5
will store 5
in a
and then return 5
In your case, you see undefined
because the return value of alert
is always undefined
.