Jump to content

Javascript simple if check


harshpandya
 Share

Recommended Posts

Here is the code - why it wont work. alert(val1 + " and " + val2); //val1 and val2 are same if(val1 == val2){ dosomething(); }else{ dosomethingnew(); insRow('myTable', searchForBack+" "+svalueBack, 'failed', 'N/A'); }Note:::: here val1 is number (val1 = 20) and val2 is string (val2 = 20)val1 is just value i assigned to variable val2 is string that i parse from bigger string.so i believe i want to check is if(val1 == val2). and it does not work in above codePlease help,Thanks,

Link to comment
Share on other sites

Not working !!!First i check the type of these var1 and var2 ::::::They both are strings for sure:: if (typeof val1 == "string") { alert('val1 is string.') } if (typeof val1 == "number") { alert('val1 is number.') } if (typeof val2 == "string") { alert('val is string.') } if (typeof val2 == "number") { alert('val1 is number.') } parseInt(val1, 10); parseInt(val2, 10); if(val1 == val2){ alert("equal"); }Did not work.... i also tried val1===val2 for strings, Please Help --

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...