score:1

Accepted answer

Looks like that's a quick way of throwing an exception when, in this case, said element property (elem.opacity) is falsey.

Running the following statement throws a "runtime" error:

alert(elem.opacity ||Â 0);

Writing that is shorter than writing:

alert(elem.opacity ? elem.opacity : throw 'some error message');

Note: the throw statement will not work as expected (writing to the console "some error message") -- as the ternary expression should return a value.

Thus, (elem.opacity ||Â 0) suffices and keeps the code concise/terse and defensive, but not very semantic ...


In Short

The following:

... (elem.opacity ||Â 0) ...

Translates to:

Throw an error if elem.opacity is undefined.


Related Query

More Query from same tag