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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With