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

  • Home
  • SEARCH
  • 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 4118442
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:57:40+00:00 2026-05-20T22:57:40+00:00

This one just stabbed me hard. I don’t know if it’s the case with

  • 0

This one just stabbed me hard. I don’t know if it’s the case with all browsers (I don’t have any other competent browser to test with), but at least Firefox has two kind of string objects.

Open up the Firebugs console and try the following:

>>> "a"
"a"
>>> new String("a")
String { 0="a"}

As you can visually observe, Firefox treats new String("a") and "a" differently. Otherwise however, both kinds of strings seem to behave the same. There is, for instance, evidence that both use the same prototype object:

>>> String.prototype.log = function() { console.log("Logged string: " + this); }
function()
>>> "hello world".log()
Logged string: hello world
>>> new String("hello world").log()
Logged string: hello world

So apparently, both are the same. That is, until you ask for the type.

>>> typeof("a")
"string"
>>> typeof(new String("a"))
"object"

We can also notice that when this is a string, it’s always the object form:

>>> var identity = function() { return this }
>>> identity.call("a")
String { 0="a"}
>>> identity.call(new String("a"))
String { 0="a"}

Going a bit further, we can see that the non-object string representation doesn’t support any additional properties, but the object string does:

>>> var a = "a"
>>> var b = new String("b")
>>> a.bar = 4
4
>>> b.bar = 4
4
>>> a.bar
undefined
>>> b.bar
4

Also, fun fact! You can turn a string object into a non-object string by using the toString() function:

>>> new String("foo").toString()
"foo"

Never thought it could be useful to call String.toString()! Anyways.

So all these experiments beg the question: why are there two kinds of strings in JavaScript?


Comments show this is also the case for every primitive JavaScript type (numbers and bools included).

  • 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-05-20T22:57:41+00:00Added an answer on May 20, 2026 at 10:57 pm

    There are two types of strings in Javascript — literal strings and String objects. They do behave a little differently. The main difference between the two is that you can add additional methods and properties to a String object. For instance:

    var strObj = new String("object mode");
    strObj.string_mode = "object"
    strObj.get_string_mode = function() { return this.string_mode; }
    
    // this converts it from an Object to a primitive string:
    str = strObj.toString();
    

    A string literal is just temporarily cast to a String object to perform any of the core methods.

    The same kinds of concepts apply to other data types, too. Here’s more on primitive data types and objects.

    EDIT

    As noted in the comments, string literals are not primitive strings, rather a “literal constant whose type is a built-in primitive [string] value”, citing this source.

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

Sidebar

Related Questions

Just could not get this one and googling did not help much either.. First
this query will just one row as a result myDataContext db = new myDataContext();
I just want to clarify one thing. This is not a question on which
This one is a case of not doing your homework.:-) Apart from dynamic loading
This one has me beat; I have a WPF window with two (important for
This one will take some explaining. What I've done is create a specific custom
This one has me kind of stumped. I want to make the first word
This one has been bugging me for a while now. Is there a way
This one has me scratching my head. I'm running Subversion 1.3.1 (r19032) on Ubuntu.
This one is a bit tedious in as far as explaining, so here goes.

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.