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 9217881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:43:58+00:00 2026-06-18T02:43:58+00:00

OK I just did it and scratched my head for a while. I tried

  • 0

OK I just did it and scratched my head for a while. I tried following on my Chrome console:

var a = [];
toString.call(a); //[object Array]
a.toString(); //""
toString(a); //[object Object] I know it's blunder but still!

What is difference between the toString and .toString I definitely know they are from different scopes (objects), but which one should be used at what time? Why is it so messy?

  • 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-18T02:43:59+00:00Added an answer on June 18, 2026 at 2:43 am

    First of all we have to clarify that toString refers to Object.prototype.toString:

    > toString === Object.prototype.toString
      true
    

    How Object.prototype.toString works is explained in section 15.2.4.2 of the specification:

    1. If the this value is undefined, return "[object Undefined]".
    2. If the this value is null, return "[object Null]".
    3. Let O be the result of calling ToObject passing the this value as the argument.
    4. Let class be the value of the [[Class]] internal property of O.
    5. Return the String value that is the result of concatenating the three Strings "[object ", class, and "]".

    toString.call(a) is the same as Object.prototype.toString.call(a) and works according to the above algorithm: this refers to the array a (because you used .call), the internal [[Class]] property has the value Array, hence the output is [object Array].

    a.toString(): Arrays overwrite the toString property, which is defined in section 15.4.4.2. In short, all array elements are concatenated and since the array is empty, you get an empty string as result.

    toString(a) is the same as Object.prototype.toString(). The argument is simply ignored. Therefore this refers to Object.prototype, which is an object and according to the algorithm mentioned above, the output is [object Object]. The output would be same for any value of a.


    which one should be used at what time?

    That depends on what you want to do. Personally I find none of the built-in toString functions particularly useful, besides for some quick and dirty debugging.


    toString.call(a) should be == a.toString()

    Well, Object.prototype.toString and Array.prototype.toString are simply two different methods, hence you get different results.

    You could argue that Object.prototype.toString should call the overwritten toString if it exists, but that’s just not how toString is implemented.

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

Sidebar

Related Questions

I just did a syntax like this mysql_real_escape_string($var = 'Hello'); print_r($var); and I got
hay all, I just did the following: a = input(give a word: ) b
I just did the following in htaccess: ErrorDocument 404 http://www.website.com My first question is,
I just did the following to to keep a different copy of my config.php
I just did something dumb with my SVN repository, I accidentally imported a load
I just did an svn merge from a branch to a trunk in my
I just did File -> New Project last night on a new project. Ah,
I just did a fresh installation of Visual Studio 2010 Ultimate and ReSharper 5.
I just did one of those auto updates of the Android SDK (API 15
I just did a fresh install of Apache server 2.2. Everything works. When I

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.