It's also common practice to make the event object argument optional and implement default behavior, like so (note that int would be the better number type to use here as you're accessing an array index):

when evt is null will casting evt.target.name equal to 0? I doubt it.
–
loxxyJan 30 '11 at 16:51

@loxxy casting null to int will give you 0, but in this case you'd be accessing a property of null first (evt.target) which will throw an error...
–
meyerteeJan 30 '11 at 17:01

Well that's what I was referring to. The above situation where the casting wont give 0 but an error.
–
loxxyJan 30 '11 at 17:05

1

The code checks for evt being null with a ternary operator: "evt ? evt.target.name : 0" is the same as "if (evt!=null){imgIndex=evt.target.name;} else {imgIndex=0;}", so there won't be an error.
–
meyerteeJan 30 '11 at 17:17