Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
173
rated 0 times [  174] [ 1]  / answers: 1 / hits: 16342  / 14 Years ago, mon, october 11, 2010, 12:00:00

Should I be using alert() for debugging; or is there a time to use alert() vs. console.log()?



I see that alert() and console.log() can return different results. I assumed that they were similar functions but just returned in different places.



Back story: my boss likes to see alerts() during development but I can't get the object details in the alert (at least not easily).



But when I run the same request through console.log, I get the object and all of it's parameters.


More From » firebug

 Answers
25

Since alert could be shown to users, it tends to be literal-minded (just using toString) so a developer has a lot of control over what's shown to the user. Unlike alert, console is designed for developers, and thus tends to try to interpret a call so as to provide information that a developer would find useful: e.g. [2, 3, 4] is a lot more useful to a developer than [object Object]. Alert should be the same in every browser; console's behavior could vary from browser to browser (including not being supported at all, as in IE).


[#95355] Friday, October 8, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
amberlykaliac

Total Points: 415
Total Questions: 100
Total Answers: 85

Location: Wallis and Futuna
Member since Tue, Mar 30, 2021
3 Years ago
amberlykaliac questions
Mon, Sep 28, 20, 00:00, 4 Years ago
Wed, Jul 29, 20, 00:00, 4 Years ago
Sun, Jul 12, 20, 00:00, 4 Years ago
Sun, May 17, 20, 00:00, 4 Years ago
;