Console Is Not Defined Javascript Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about javascript error console is undefined hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges
Javascript Error Console Chrome
Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. javascript error console safari Join them; it only takes a minute: Sign up Internet Explorer: “console is not defined” Error up vote 19 down vote favorite 4 I was using console.log() in some JavaScript I wrote and an error of: console is not
Javascript Error Console Firefox
defined was thrown in Internet Explorer (worked fine in other browsers). I have replaced it with: if (console) console.log("..."); If console is undefined, I would expect the condition to evaluate as false. Ergo, the statement console.log wouldn't be executed and shouldn't throw an error. Instead, an error of: console is not defined at character 4 is thrown. Is this a IE bug? Or is that "if" condition really illegal? It seems absurd because if if (console) is illegal, javascript output console then if (console==undefined) should be illegal too. How are you supposed to check for undefined variables? javascript internet-explorer internet-explorer-8 console undefined share|improve this question edited Nov 27 '13 at 11:48 Rohwedder 5043923 asked Mar 15 '12 at 17:36 matteo 89642141 13 console doesn't exist in IE unless the console is actually open. –Dagg Nabbit Mar 15 '12 at 17:38 BTW you may have some another console object, hence foolproof solution would be to check that console.log exists and is a function. –kirilloid Mar 15 '12 at 17:41 2 possible duplicate of 'console' is undefined error for internet explorer –Dagg Nabbit Mar 15 '12 at 17:41 2 Did I really write "Ergo"??? Or is that what @Matt McDonald edited? –matteo Apr 24 '12 at 21:41 Ergo was added by last editor "user1385191" :) –JOM May 14 '13 at 9:55 add a comment| 8 Answers 8 active oldest votes up vote 24 down vote accepted If console itself doesn't exist at all, it throws an error because you're accessing an undefined variable. Just like if(abc) {} throws an error. Since console resides in window, and window does always exist, this should work: if(window.console) ... Basically, accessing an property that doesn't exist is free and doesn't throw an error (it just evaluates to undefined, failing the if condition). However, it is illegal to access an undeclared variable. share|impr
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us
Jquery Error Is Not Defined
Learn more about Stack Overflow the company Business Learn more about hiring developers
Firefox Write To Console
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack console verb Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up js override console.log if not defined up http://stackoverflow.com/questions/9725111/internet-explorer-console-is-not-defined-error vote 23 down vote favorite 8 Which solution do you recommend, the second is simpler ( less code ), but there are drawbacks on using it ? First: (Set a global debug flag) // the first line of code var debug = true; try { console.log } catch(e) { if(e) { debug=false; } }; // Then later in the code if(debug) { console.log(something); } Second: override console.log http://stackoverflow.com/questions/3767924/js-override-console-log-if-not-defined try { console.log } catch(e) { if (e) { console.log = function() {} } }; // And all you need to do in the code is console.log(something); javascript console firebug share|improve this question edited Dec 15 '13 at 16:37 blunderboy 10.7k1158103 asked Sep 22 '10 at 9:30 Radu Maris 2,65622445 add a comment| 7 Answers 7 active oldest votes up vote 51 down vote accepted Neither, but a variation of the second. Lose the try...catch and check for existence of the console object properly: if (typeof console == "undefined") { window.console = { log: function () {} }; } console.log("whatever"); share|improve this answer edited Sep 22 '10 at 9:55 answered Sep 22 '10 at 9:35 Andy E 200k49354370 1 Presumably you either want to do this.console = ... or var console = ...? As you have it at the moment, you'd get an error in ECMAScript 5 strict mode. –Tim Down Sep 22 '10 at 9:48 1 @Tim: thanks, it was an oversight. I think window.console would be best for portability. –Andy E Sep 22 '10 at 9:56 1 Portability in the sense of being able to move this code into a function, rather than portability
JavaScript Forum View Course https://teamtreehouse.com/community/uncaught-referenceerror-console-is-not-defined 498 points Submitted by ainhlumayo over 4 years ago What does the error (ReferenceError: javascript error Console is not defined Oops, try again.) mean, and what did I do wrong? Please help I'm new so Javascrift is like a foreign language to me. Thanks javascript error console 0 votes permalink In general, a reference error means that you used a word that JavaScript didn't recognize. It's neither a pre-existing part of the JavaScript vocabulary, nor a word that you've assigned a meaning to. With regard to your specific reference error it'd help to see the code you used to get the error, but I'm guessing you were trying to use console.log(), but got some part of the syntax wrong? 811 points Submitted by mstegosaurus over 4 years ago
to use myscript.js within a basic website ("Programming.html") that is in the same directory. In the console, "Uncaught ReferenceError Console is not defined" is the message I get. Below is the source code for myscript.js, and Programming.html, respectively - please let me know if I need to format either differently to allow others to see it.Thanks! '''Console.log("Hello from myscript.js");''' '''