It's for event listeners.
IE6-IE8 used a totally different event method than the W3C standard.
When an event fires, a W3C-standard browser will pass an event object in the callback:
function keyPressed (e) { /* do stuff with e */ }
In your case, it's keydown
(or something else using keyCode
).
IE didn't support this, instead it had window.event
which was updated every time an event happened.
So your function is checking to see if an object was passed into it:
evt = (evt) ? evt : window.event;
// does `evt` exist, and is it anything but '', 0, false, null, undefined, NaN
// yes: evt = itself (W3C)
// no: evt = window.event (IE6-8)
Then the code asks if evt.which
exists, to try to figure out where to get the keyCode from.
evt.keyCode
is what you should be using for modern browsers, in the case of keydown
and keyup
.