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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:09:50+00:00 2026-05-25T03:09:50+00:00

There are plenty of tutorials for == and === so please don’t guide me

  • 0

There are plenty of tutorials for == and === so please don’t guide me to a basic tutorial, my question is a bit more specific:

For example http://www.w3schools.com/jsref/jsref_obj_string.asp states that:

Syntax:

var txt = new String("string");

// or more simply:
var txt = "string";

Good, but what about this?

alert(new String("a") == new String("a")); // false
alert("a" == "a"); // true

var a = new String("a");
var b = new String("a");
alert(a == b); // false

var c = "a";
var d = "a";
alert(c == d); // true

alert(c === d); // true
alert (a === c); // false

Of course nobody calls new String() anyway, but is it something about the equality failing because new String() is handled as an object not as a string?

And of course W3Schools is not the most trusted source but I would have expected all of the above alerts to say true.

Please explain.

  • 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-25T03:09:50+00:00Added an answer on May 25, 2026 at 3:09 am

    The “surprising results” come from the way Javascript handles equality for Objects, plus the confusion that arises between string literals and String objects. From the Mozilla reference guide for the == operator:

    If the two operands are not of the same type, JavaScript converts the
    operands then applies strict comparison. If either operand is a number
    or a boolean, the operands are converted to numbers if possible; else
    if either operand is a string, the other operand is converted to a
    string if possible. If both operands are objects, then JavaScript
    compares internal references which are equal when operands refer to
    the same object in memory
    .

    You can experience the same behavior with numbers:

    new Number(5) == new Number(5) // false
    

    And clarify your mind by:

    typeof "string" // string
    typeof new String("string") // object
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

there are plenty of tutorials showing how to blend two images in opencv: http://opencv.itseez.com/doc/tutorials/core/adding_images/adding_images.html
Is there a succinct but complete example project or tutorial that brings together the
There are plenty of tutorials how to create multilanguage RESX files and how to
there are plenty of tutorials on how to request and parse a list of
I know there are plenty of tutorials about integrating C++ into Java, but whats
There are plenty of script/tools for counting line of code, and some to count
There's plenty of information on running Java apps as services, but I need to
There are plenty of PHP frameworks out there as many of you know, and
There are plenty of 'pretty-printing' visualization libraries for Javascript. E.g. those listed here. Googling
Dynamic languages are on the rise and there are plenty of them: e.g. Ruby,

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.