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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:34:08+00:00 2026-06-02T20:34:08+00:00

null and undefined don’t have a toString or valueOf method. Afaik using String calls

  • 0

null and undefined don’t have a toString or valueOf method. Afaik using String calls the toString method of its parameter (e.g. String({}) => [object Object]).

Why do String(null) or String(undefined work then? It doesn’t implicitly do Object.prototype.toString.call(null). because that evaluates to [object Null].

[edit]: from the spec ECMA-262/5th edition (page 48). This doesn’t add to clarification, I’d say:

/*
Table 13 — ToString Conversions  
-------------------------------------------------------------------------
Argument Type  | Result  
-------------------------------------------------------------------------
Undefined      | "undefined"
Null           | "null"  
Boolean        | If the argument is true, then the result is "true".
...            | ...
*/
  • 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-02T20:34:11+00:00Added an answer on June 2, 2026 at 8:34 pm

    After reviewing my previous answer, it seems a complete overhaul of my previous answer is necessary. I was way over complicating it, as the short answer is that these are standards-specified special cases.

    The specification for String() (String used as a function):

    15.5.1.1 String ( [ value ] )

    Returns a String value (not a String object) computed by ToString(value). If value is not supplied, the empty
    String “” is returned.

    The ToString function (that exists internally, not in userland) is defined as follows (9.8):

    “The abstract operation ToString converts its argument to a value of type String according to Table 13”

    Argument Type | Result
    Null | "null"
    Undefined | "undefined"
    

    This means that String(null) and String(undefined) go into this special table of types and just return the string values valued "null" and "undefined".

    A user-land pseudo-implementation looks something like this:

    function MyString(val) {
        if (arguments.length === 0) {
            return "";
        } else if (typeof val === "undefined") {
            return "undefined";
        } else if (val === null) {
            return "null";
        } else if (typeof val === "boolean") {
            return val ? "true" : "false";
        } else if (typeof val === "number") {
            // super complex rules
        } else if (typeof val === "string") {
            return val;
        } else {
            // return MyString(ToPrimitive(val, prefer string))
        }
    }
    

    (Note that this example ignores the constructor case (new MyString()) and that it uses user-land concepts rather than engine-land.)


    I got a bit carried away and found an example implementation (V8 to be specific):

    string.js:

    // Set the String function and constructor.
    %SetCode($String, function(x) {
      var value = %_ArgumentsLength() == 0 ? '' : TO_STRING_INLINE(x);
      if (%_IsConstructCall()) {
        %_SetValueOf(this, value);
      } else {
        return value;
      }
    });
    

    macros.py:

    macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : NonStringToString(arg));
    

    runtime.js:

    function NonStringToString(x) {
      if (IS_NUMBER(x)) return %_NumberToString(x);
      if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
      if (IS_UNDEFINED(x)) return 'undefined';
      return (IS_NULL(x)) ? 'null' : %ToString(%DefaultString(x));
    }
    

    The NonStringToString (which is essentially what is of interest), is luckily defined in psuedo-JS-land. As you can see, there is indeed a special case for null/true/false/undefined.

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

Sidebar

Related Questions

I have used have_db_column in other project, I don't understand the undefined method error.
I'm using Ruby version 1.8.7 Rails version 3.0.3 I have a method called alive
!! always works fine for converting String , undefined , Object and Number types
How do I determine if a variable is undefined or null ? My code
How can I return null instead of a 'undefined' from a select element. Basically
The standard says that dereferencing the null pointer leads to undefined behaviour. But what
Is it true that the following yields undefined behavior: void * something = NULL;
As per http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf , JavaScript has 6 types: undefined , null , boolean ,
Possible Duplicate: C#: Passing null to overloaded method - which method is called? Here
I have a javascript class with an array property. I'm created a method on

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.