Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8385887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:46:46+00:00 2026-06-09T17:46:46+00:00

In Chrome the console object defines two methods that seem to do the same

  • 0

In Chrome the console object defines two methods that seem to do the same thing:

console.log(...)
console.dir(...)

I read somewhere online that dir takes a copy of the object before logging it, whereas log just passes the reference to the console, meaning that by the time you go to inspect the object you logged, it may have changed. However some preliminary testing suggests that there’s no difference and that they both suffer from potentially showing objects in different states than when they were logged.

Try this in the Chrome console (Ctrl+Shift+J) to see what I mean:

> o = { foo: 1 }
> console.log(o)
> o.foo = 2

Now, expand the [Object] beneath the log statement and notice that it shows foo with a value of 2. The same is true if you repeat the experiment using dir instead of log.

My question is, why do these two seemingly identical functions exist on console?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:46:47+00:00Added an answer on June 9, 2026 at 5:46 pm

    In Firefox, these function behave quite differently: log only prints out a toString representation, whereas dir prints out a navigable tree.

    In Chrome, log already prints out a tree — most of the time. However, Chrome’s log still stringifies certain classes of objects, even if they have properties. Perhaps the clearest example of a difference is a regular expression:

    > console.log(/foo/);
    /foo/
    
    > console.dir(/foo/);
    * /foo/
        global: false
        ignoreCase: false
        lastIndex: 0
        ...
    

    You can also see a clear difference with arrays (e.g., console.dir([1,2,3])) which are logged differently from normal objects:

    > console.log([1,2,3])
    [1, 2, 3]
    
    > console.dir([1,2,3])
    * Array[3]
        0: 1
        1: 2
        2: 3
        length: 3
        * __proto__: Array[0]
            concat: function concat() { [native code] }
            constructor: function Array() { [native code] }
            entries: function entries() { [native code] }
            ...
    

    DOM objects also exhibit differing behavior, as noted on another answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really love the Chrome console because it autocompletes all the object methods for
Getting that error in my javascript console(in Chrome) with a collada object I'm attempting
Possible Duplicate: Intercept calls to console.log in Chrome Can I extend the console object
I used the Chrome Console to write a simple statement: console.log(4) and received the
Does anyone know of a way to save the console.log output in Chrome to
Whenever I console.log() a Backbone.js Collection, Google Chrome's console shows the letter d unlike
If you printout File object in Chrome console with something simple like this: <input
i need to template with handlebars an array of json object:(by chrome console) [object,object,object,object]
Here is my brief HTML document. Why is Chrome Console noting this error: Uncaught
Chrome's console reports an error. It lists the name of a function -- presumably,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.