What is different from console.log and console.dir?

Possible duplicate:
What is the difference between console.dir and console.log?

I recently found out about the existence of console.dir() .

Looking through MDN , I did not quite understand what the real difference between this and console.log . Both of them show the same output (but .dir shows some properties), is that so?

What function should I use when debugging / developing?

EDIT: I just figured out an existing question that answers my thoughts: What is the difference between console.dir and console.log?

+8
javascript debugging html coding-style
source share
1 answer

The way information is presented is different. For example, in Firebug, if I do this:

 a = { foo: "foo", bar: "bar" }; 

And then I:

 console.log(a) 

I get:

 Object { foo="foo", bar="bar"} 

If I do this:

 console.dir(a) 

I get:

 bar "bar" foo "foo" 

If I had nested objects, I would have a little twisty controls (MDN calls them “disclosure triangles”) so that I can easily delve into the properties of the object.

Depending on the tools used YMMV.

+11
source share

All Articles