On the MDN page for the wheel event, there is a code sample which includes the following at lines 30-31:
function( originalEvent ) {
!originalEvent && ( originalEvent = window.event );
The second line seems to take a number of shortcuts that rely on the way JavaScript evaluates boolean expressions internally. If I understand correctly, its purpose is to set originalEvent to window.event if no argument is passed. Its action is the same as the following:
if (!originalEvent) {
originalEvent = window.event;
}
or
orginalEvent = (originalEvent) ? orginalEvent : window.event;
What advantages are there in using the construction from the MDN site?
Looking cool pretty much.
I was going to say terseness, but the following is just as short, and it's clear at a glance what's going on:
Do note however that their sample doesn't rely on any "internal" order of operations or anything sinister. Operator short-circuiting (which is what this is called) is a very well defined and popular part of many languages, of which Javascript is just an example. You could write the same exact statement in C and it would work fine.