Jump to content
  • Advertisement
Sign in to follow this  
Awoken

true != true in JavaScript ? WHAT THE H*&#?

This topic is 531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So this is was my issue, I had an if statement

console.log( a );
if( a ){
   console.log('made it here');
}
console.log( a );

and a was being assigned by dat.GUI, you had a drop down menu and it would assign either true of false to a.

my console output would read

 

true

true

 

And I'm scratching my head cursing the computer for never getting me to 'made it here'

 

then I test a before dat.GUI gets ahold of it and it spits out

 

true

 

Now I'm color blind and seeing the difference between the two was only achieved once I happened to be looking at the screen from the right angle.  Then I realised that dat.GUI wasn't setting it to true but rather 'true'.  :angry:

Share this post


Link to post
Share on other sites
Advertisement
if('true') console.log('made it here');

Seems to work for me? Or am I missing something? Quick google stackoverflow result on evaluating strings seems to confirm. At least it's boolean now :P.

Share this post


Link to post
Share on other sites
if('true') console.log('made it here');

Seems to work for me? Or am I missing something? Quick google stackoverflow result on evaluating strings seems to confirm. At least it's boolean now :P.

 

Yeah, you're absolutely right.  this was a while back that I encountered this, but the most frustrating yet for me.  I think the problem was I was trying to get the value to false, but instead it was setting it to 'false' and if you if( 'false') it still logs it as true.  I just had the boolean values reversed.

Edited by Awoken

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!