Skip to content

Debugging in JavaScript

5. March 2013

Debugging in JavaScript seemed to be, in the first moment I began with it, to be very complicated. But with a closer look it is really simple.

I use Firebug as debugging tool to my Firefox! This provides basically the possibility to read debugs.

In JavaScript, you have very simple possibilities to print some informative values to the debug window using the “console” command (e.g.: console.log(“My output!”);)

The cool thing is that, similar to Pyhons integrated function “dir()”, you can also print ancillary methods and objects by “console.dir();”

By this I can get even all ancillary information on console by:

console.dir(console);

This command delivers all possible console – functions:

assert
clear
count
debug
dir
dirxml
error
exception
group
groupCollapsed
groupEnd
info
log
profile
profileEnd
table
time
timeEnd
timeStamp
tracewarn

An functional equivalent, that I used before recognising the coolness of “console”, looks like this:

function dir(object) {
    stuff = [];
    for (s in object) {
    stuff.push(s);
    }
    stuff.sort();
    return stuff;
}

I found this function here!

Advertisements

From → JavaScript, tutorial

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: