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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:23:07+00:00 2026-05-27T15:23:07+00:00

I have this code: … var id1 = playerTick.gameId; var id2 = that.gameId; if(id1

  • 0

I have this code:

...
var id1 = playerTick.gameId;
var id2 = that.gameId;
if(id1 === id2)
 {}else{
throw "GameController instantiated with gameId '" + id2 + "' but tick has gameId '" + id1 + "'";
}

And when I run it, I get the message:

GameController instantiated with gameId ‘game1’ but tick has gameId ‘game1’

How can === fail when it prints correctly ‘game1’ as the value of both properties? As a test, I have made this which works:

var g = "game1";
var g2 = "game1"
alert(g === g2); // Alerts true

Does anyone have an idea of ANY theoritical explanation of how my === can fail but the error message prints the same text? The type of both values are object.

Thankyou in advance.

UPDATE:

THE PROBLEM

It turned out, as all the replies pointed out (and thankyou for that), that the types were not identical. One of the was not a string resulting in === evaluating to false.

The problem occurred after using this function to retrieve a query parameter:

function querystring(key) {
       var re=new RegExp('(?:\\?|&)'+key+'=(.*?)(?=&|$)','gi');
       var r=[], m;
       while ((m=re.exec(document.location.search)) != null) r.push(m[1]);
       return r;
}

THE FIX

function querystring(key) {
           var re=new RegExp('(?:\\?|&)'+key+'=(.*?)(?=&|$)','gi');
           var r=[], m;
           while ((m=re.exec(document.location.search)) != null) r.push(m[1]);
           return r.toString(); // Ensures that a string is returned
    }
  • 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-27T15:23:07+00:00Added an answer on May 27, 2026 at 3:23 pm

    You said they are objects so of course they are not the same:

    var g = new String("game1"),
        g2 = new String("game1");
    
    g===g2 //false
    g==g2 //false
    

    Variables that “hold objects” actually are just references to objects. Unless both the variables refer the exact same object in memory, they will not be equal no matter what the content unless you compare g.toString() === g2.toString() //true.

    Note that when you do "hello"+var, var is automatically converted toString form:

    null + "hello" === "nullhello"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that I have written in Ruby, but when trying to
I have this code for doing an ajax request to a webservice: var MyCode
I have this code: http://jsfiddle.net/bUPWS/1/ but #div2 overflows #div1. How to bring the overflowed
I have this code to create a config.ini file with Zend Framework but I
I have this code : for (var i = 0; i < result.length; i++)
Have this code: var gradient = ctx.createLinearGradient(0,0, 20, 0); gradient.addColorStop(0.8, rgb(250,250,0)); gradient.addColorStop(1, rgb(150,150,0)); ctx.fillStyle
I have this code but it doesn't work! public class Trial { public static
I have this code that I call on each touch event that render an
I have this code, that draws an image. private void timer1_Tick(object sender, EventArgs e)
I have this code var contacts = dr.mktDoctorContacts .GroupBy(x => x.ContactType) .Select(zb => new

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.