Click here to Skip to main content
15,909,530 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am having a problem in JS,i have two variables a and b
both have values like

a= '1716e362-5afe-4c80-9fff-880aaf109638'

b= '1716e362-5afe-4c80-9fff-880aaf109638'

I have applied a condition like

if(a== b)
{
//do some thing
}


The problem is arising is that the if condition is appearing false

I also tried === but its still showing false :(

Can any one tell me whats the reason??

a and b values are same
Posted

It must function correctly , Check it like

<script type="text/javascript">

var a = '1716e362-5afe-4c80-9fff-880aaf109638';
var b = '1716e362-5afe-4c80-9fff-880aaf109638';
if(a==b)
{
 alert("true");
}
else
{
 alert("false");
}

</script>


If alerts true than same else alerts false

Hope it helps
 
Share this answer
 
My guess is that something is changing a or b (or both). Try using a Javascript debugger (F12 in Internet Explorer, Ctrl-Shift-I in Chrome or use Firebug for Firefox) and add a breakpoint at your "if" statement. You should then be able to examine the values of a and b.
 
Share this answer
 
You can also do the following,

XML
<script type="text/javascript" language="javascript">
        var a = '1716e362-5afe-4c80-9fff-880aaf109638';
        var b = '1716e362-5afe-4c80-9fff-880aaf109638';
        if (parseInt(a) == parseInt(b)) {
            alert("Match");
        }
        else {
            alert("UnMatch");
        }
    </script>
 
Share this answer
 
Comments
Sandeep Mewara 18-May-11 4:42am    
parseInt?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900