Destramic Posted November 1, 2014 Share Posted November 1, 2014 i've google but no luck on finding what i need....is there a way in javascript to compare 2 variables ie. var him = "jack"; var her = "jill"; if (him == her){ alert('same name'); } thank you Quote Link to comment https://forums.phpfreaks.com/topic/292220-comparing-2-variable-values/ Share on other sites More sharing options...
codefossa Posted November 1, 2014 Share Posted November 1, 2014 That should work fine. // http://jsfiddle.net/qcr1qws4/ var first = "Thomas"; var second = "Jack"; if (first == second) alert("Same Name"); if (first == "Thomas") alert("First person's name is Thomas."); Quote Link to comment https://forums.phpfreaks.com/topic/292220-comparing-2-variable-values/#findComment-1495492 Share on other sites More sharing options...
Alex_ Posted November 1, 2014 Share Posted November 1, 2014 I'm confused what you mean by "comparing" two variables since that's what you did yourself in the main post. Also you should use tripple '=' operator, not double, if you want to be sure the two values are actually the same, because then it makes sure the type of the variable is the same as well. For instance a string of "1" and an integer of 1 would be "the same" when using double '=' operator. Example: var first = "1"; var second = 1; console.log(first == second); //true console.log(first === second); //false, different types. But could you please elaborate more what you mean by "comparing" two variables ? Because like I said, it looks like you did it yourself in the main post. Quote Link to comment https://forums.phpfreaks.com/topic/292220-comparing-2-variable-values/#findComment-1495494 Share on other sites More sharing options...
Destramic Posted November 1, 2014 Author Share Posted November 1, 2014 well this is embarrassing...yeah it works now for me...well sorry to have wasted your time, but thank you for you posts Quote Link to comment https://forums.phpfreaks.com/topic/292220-comparing-2-variable-values/#findComment-1495496 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.