Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What differs between console.log and console.dir? [duplicate]

Possible Duplicate:
What’s the difference between console.dir and console.log?

I have recently learnt the existence of console.dir().

After looking through MDN, I did not clearly understand what is the real difference between this and console.log. They both show the same output (but .dir shows some properties), is that it?

Which function should I use when debugging/developping?

EDIT: I just found out an existing question which answers my thoughts: What's the difference between console.dir and console.log?

like image 551
Jeff Noel Avatar asked Jan 07 '13 16:01

Jeff Noel


1 Answers

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

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

And then I do:

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 the little twisty controls (MDN calls them "disclosure triangles") so that I could easily dig deeper into the object properties.

Depending on the tools you are using, YMMV.

like image 100
Matt Burland Avatar answered Oct 20 '22 10:10

Matt Burland