A.I on the 1s and 0s

Alnur Ismail is a developer for Microsoft

A better alternative to using alert() for debugging.

We've all used, and unfortunately some people continue to use, alert() to help debug JavaScript. Thankfully the Microsoft Ajax Library has a Sys.Debug class that exposes methods for logging messages to the browser’s JavaScript console. For reference:

To log a message to the console use: Sys.Debug.trace(“Log this message to the console”);

To dump an object use: Sys.Debug.traceDump(someObject);

If you don’t have a JavaScript console download the Web Development Helper for IE, and Firebug for Firefox, or add the following textarea element to your page:
<textarea id=”TraceConsole” rows=”50” cols=”50”></textarea>
This will display all your trace messages in the textarea.

Comments

Community Blogs said:

Most people use alert() to debug their JavaScript, but the Microsoft Ajax Library has a better alterative

# January 13, 2009 6:15 AM

Rodrigo said:

The best way to debug Javascript for me its by adding the debugger keywork inside the javascript function I want to debug.

When the function is executed the browser gives you the option to debug the page with Visual Studio (any version).

Just remember to uncheck the "Disable script debugging " on Internet Explorer configuration.

# January 13, 2009 8:40 AM

Nasco said:

I totally agree with Rodrigo.

There is also a breakpoints functionality in Firebug that you can use with Firefox. :)

# January 13, 2009 9:18 AM

Abhilash said:

"The best way to debug Javascript for me its by adding the debugger keywork inside the javascript function I want to debug."

What does that mean?

How to do that?

Just dont know abt it, dts y asking?

Thankz

# January 19, 2009 8:57 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)