Debugge Javascript

Can I debugge Javascript code to see which values take my variables?

If so, How can I do it.

thanks so much

See http://javascript.about.com/od/problemsolving/ig/JavaScript-Debugging/ to see where to find the debugger option in whichever browser you are using.

If you’re using Google Chrome, there are some highly specific details about using the JavaScript console at http://code.google.com/chrome/devtools/docs/console.html

If you’re not comfortable using a debugger, another option is to insert alert() statements in your code to check values of variables or to check if parts of your code are ever reached.

If you are going to do that then test in IE9 or Opera where the alert gives you an option to kill subsequent alerts just in case the script gets stuck in a loop.

If not using those browsers you can go to your Windows Task Manager (obviously if using Windows) to stop the process if it is stuck in an infinite loop.

Using chrome or firefox w/ firebug console.log() is probably the simplest means of dumping variables and testing code completion.

But that means crashing the entire browser - The way I suggested only crashes the script and leaves the rest of the web page and everything else in the browser intact.

So your suggestion is the equivalent of lopping off someone’s head to get rid of a pimple on their nose.

Possibly the second quickest perhaps.

Just opening the debugger and setting a breakpoint at the spot in the code you want to check is the quickest.

yep, so what? :wink:

It’s not an issue for me. I just then edit the code that caused the infinite loop and then retest it by reopening the page in the browser. If closing the browser is an issue for someone then obviously using the Task Manager is not an option :lol:

The issue is that commonly the web browser is being used for several other tasks, with 20 other tabs being opened or other purposes.
Don’t apply a sledgehammer when a precision instrument can be easily employed instead.

I don’t see the point you are making.

What I suggested is just another option which in my case with the way I do things, using the task manager is not an issue.

As I said in my previous post. If closing the browser is an issue for someone, then obviously closing the browser with the task manager is not an option - but for me it is :slight_smile:

Most people have more than one page open in their browser at the same time and your solution is to cancel all of them at once rather than just the page with the problem. That’s the point being made - you are perhaps closing down four or five web sites that you had open just because of an issue with the one page. If one of those pages happened to be one where you were part way through a bank transaction then it could cost you a lot of money as well.

Now you’re just resorting to posting fluff (which is against the rules) :rofl: because all you are doing is repeating what paul_wilkins posted earlier and I replied with

What I suggested is just another option which in my case with the way I do things, using the task manager is not an issue.

As I said in my previous post. If closing the browser is an issue for someone, then obviously closing the browser with the task manager is not an option - but for me it is :slight_smile: