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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:06:33+00:00 2026-06-18T12:06:33+00:00

Does anyone know the difference between String and string in TypeScript? Am I correct

  • 0

Does anyone know the difference between String and string in TypeScript? Am I correct in assuming that they ought to be the same?

var a: String = "test";
var b: string = "another test";
a = b;
b = a; // this gives a compiler error!

Current version of the compiler says:

Type 'String' is not assignable to type 'string'.
  'string' is a primitive, but 'String' is a wrapper object.
     Prefer using 'string' when possible.

Is that a bug?

  • 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-18T12:06:34+00:00Added an answer on June 18, 2026 at 12:06 pm

    Here is an example that shows the differences, which will help with the explanation.

    var s1 = new String("Avoid newing things where possible");
    var s2 = "A string, in TypeScript of type 'string'";
    var s3: string;
    

    String is the JavaScript String type, which you could use to create new strings. Nobody does this as in JavaScript the literals are considered better, so s2 in the example above creates a new string without the use of the new keyword and without explicitly using the String object.

    string is the TypeScript string type, which you can use to type variables, parameters and return values.

    Additional notes…

    Currently (Feb 2013) Both s1 and s2 are valid JavaScript. s3 is valid TypeScript.

    Use of String. You probably never need to use it, string literals are universally accepted as being the correct way to initialise a string. In JavaScript, it is also considered better to use object literals and array literals too:

    var arr = []; // not var arr = new Array();
    var obj = {}; // not var obj = new Object();
    

    If you really had a penchant for the string, you could use it in TypeScript in one of two ways…

    var str: String = new String("Hello world"); // Uses the JavaScript String object
    var str: string = String("Hello World"); // Uses the TypeScript string type
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know what the difference between mmap(2) and mmap(3) is? Man section 3
Does anyone know the difference between mcrypt_generic and mcrypt_encrypt when it comes to encryption
Does anyone know the real difference between the two ways of type casting in
Does anyone know the difference between those two?
Does anyone know the difference between System::Collections::ObjectModel::ReadOnlyDictionary and Microsoft::TeamFoundation::Client::ReadOnlyDictionary ?
Does anyone know what's the performance difference between using valueForKeyPath with collection operator vs
Does anyone know the difference between using VarChar(255) and VarChar(65536) ? Here's what I
Does anyone know what the difference is between the two web service endpoints ReportService2005.asmx
Does anyone know what's the difference between using breakpoints and calling DebugBreak() func. for
Does anyone know difference between Struts2 and Spring 3 MVC. I know the difference

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.