SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Debugge Javascript

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

    If so, How can I do it.

    thanks so much

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,825
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    See http://javascript.about.com/od/probl...ipt-Debugging/ to see where to find the debugger option in whichever browser you are using.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    If you're using Google Chrome, there are some highly specific details about using the JavaScript console at http://code.google.com/chrome/devtoo...s/console.html
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,825
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by webdev1958 View Post
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  7. #7
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,151
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    Using chrome or firefox w/ firebug console.log() is probably the simplest means of dumping variables and testing code completion.
    The only code I hate more than my own is everyone else's.

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,825
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by webdev1958 View Post
    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.
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  9. #9
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,825
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by oddz View Post
    Using chrome or firefox w/ firebug console.log() is probably the simplest means of dumping variables and testing code completion.
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  10. #10
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    But that means crashing the entire browser....
    yep, so what?

    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

  11. #11
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by webdev1958 View Post
    yep, so what?
    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  12. #12
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  13. #13
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,825
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by webdev1958 View Post
    I don't see the point you are making.
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  14. #14
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    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) 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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •