Search code examples
javascriptminify

understand minified javascript code


I came across this piece of JS code on a minified library that is puzzling me:

...
return e.input || L(), e.addTest = function(a, b) {
...

I played with it on a jsFiddle without much luck understanding what is happening.

I would like to know:

  1. when does it return? always apparently.
  2. what does it return? on my test it returns undefined... why?
  3. when is the code L() executed? Only if e.input returns false?
  4. when is e.addTest set? according to my test always... why?

Solution

  • 1. when does it return?
    always.

    2. what does it return? on my test it returns indefined... why?
    if you alert alert it alerts undefined

    3. when is the code L() executed?
    if e.input is false

    4. when is e.addTest set?
    The comma operator evaluates both of its operands (from left to right) and returns the value of the second operand.

    This is the unminified code in your case:

    if (e.input) {
        L();
    }
    e.addTest = function(a, b) {};
    return e.addTest;