I got this code when learning JavaScript:
myLink.onmouseover = showLinkAttr;
function showLinkContent(evt) {
if (evt) {
var url = evt.target;
}
else {
evt = window.event;
var url = evt.srcElement;
}
..............
I don't know why we need to check event handler parameter evt before creating it. My thinking here is this code is redundant because evt doesn't exist (this code is in the beginning of the script file), show we should create it without checking it, like this:
myLink.onmouseover = showLinkAttr;
function showLinkContent(evt) {
evt = window.event;
var url = evt.srcElement;
However, as I am new to JavaScript, and the code below was written by an expert. So, could you tell me why she using it instead of the one I wrote below?