I knew what the problem was just by reading the name of your question on the SO homepage. And reading the code in the question confirms this. You have a problem: line console.log(catName);
IE (and some other browsers) do not initialize the console
object until the developer window opens.
Prior to this, an attempt to use console
will return undefined
and cause your script to stop working.
The first lesson here is not to leave debugging code in your program after you are done with it. Console calls should only be present during program testing; when you are done with them, take them out.
The second lesson is that if you need to have console
calls in your code, you must wrap them with code that checks to see if the console
exists before it tries to use it. There are several ways to do this, from a simple if(console) {console.log(...);}
to writing your own debug class. How you do this is up to you, but itβs usually a good idea to write all of the console
code this way, even if you are just doing a little debugging to avoid the problem you are facing.
Hope this helps.
source share