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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:41:16+00:00 2026-06-13T18:41:16+00:00

If you call Object.prototype.toString.call(anything) the result is always [object Something] , where Something could

  • 0

If you call Object.prototype.toString.call(anything) the result is always [object Something], where Something could be one of several things. My question is why is the “object” part there? It seems superfluous to always have it there. It doesn’t tell you anything about the argument which was passed in.

Object.prototype.toString.call(null);
=> [object Null]

Object.prototype.toString.call(undefined);
=> [object Undefined]

Since null and undefined aren’t objects (and fails CheckObjectCoercible), the “object” part really, really seems meaningless.

I have to think there was some reason originally that the “object” part was put there, even if the reason has been lost in the time since, and it’s now just preserved for historical reasons.

Can anyone help shed some light on this?


To be clear, I already know how Object.prototype.toString can be used to get the [[Class]] (type) of an object. My question concerns the reason for the format of the returned string — specifically the “object” part at the beginning. I want to know if there was ever a reason for this part or if there is a possible future reason for this part. Maybe in the future it could return something other than “object”? Can I expect it to always return “object”? If so, why does it even return it? Who wants a function to always return the same thing no matter what the input is?

  • 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-13T18:41:19+00:00Added an answer on June 13, 2026 at 6:41 pm

    Annex F of the ES5.1 specification says this about Object.prototype.toString:

    15.2.4.2: Edition 5 handling of undefined and null as this value caused existing code to fail. Specification modified to maintain compatibility with such code. New steps 1 and 2 added to the algorithm.

    This is a correction that was made in the ES5.1 spec. Prior to ES5, passing null or undefined to toString always caused the global object to be passed instead. Strict mode related changes in ES5 cause null and undefined to be passed without modification. As specified in ES5, passing null or undefined to Object.prototype.toString caused a TypeError exception. This exception broke some existing code so we had to fix the spec to not throw in that case.

    So what should toString return for null and undefined? It turns out that a lot of existing code also expects Object.prototype.toString to always return a string of the form "[object *]". So, we decided to make null and undefined produce "[object Null]" and "[object Undefined]".

    This seems to have worked and generally permitted existing ES3-based code to keep working in the presence of the strict mode related changes in ES5/5.1.

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

Sidebar

Related Questions

Why would the following be the result in ES5 non-strict mode? Object.prototype.toString.call(null); => [object
I'm actively learning javascript, and I came across the following statement: Object.prototype.toString.call([]); And I
({}).toString.call(Number.prototype) === "[object Number]" The Number prototype object is itself a Number object (its
Is there a manual way to call a COM object in the GAC in
I understand why you need to use Object.prototype.toString() or String() for typechecking arrays, but
If I set a function to Object.prototype, and try to call the function from
Object.prototype.e = function() { [].forEach.call(this, function(e) { return e; }); }; var w =
How come Object.prototype.toString === toString ? If I have this in the global scope:
From: http://ejohn.org/apps/learn/#2 Function.prototype.bind = function(){ var fn = this, args = Array.prototype.slice.call(arguments), object =
When i call object.Dispose() ; Will CLR immediately destroy the object from memory or

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.