I\'m new to JavaScript and therefore confused for the variable scope... I\'m trying to load an image, and replace it with another URL when it doesn\'t exist. I have to do it
You are calling the functions, not assigning!
img.onload = onLoadHandler(); img.onerror = onErrorHandler();
needs to be
img.onload = onLoadHandler; img.onerror = onErrorHandler;