Saturday, 15 February 2014

json - Javascript comparing number get from property of an Object as String -



json - Javascript comparing number get from property of an Object as String -

i'm stuck hours in weird situation 1 number property of json received server fails simple equality test.

var form = {'answer':'','categorydisplay':'dbadmin','creationdate':null,'id':0,'question':'','techjobdisplay':null,'techjobid':65}; var seltechjobid = form.techjobid; var thisval = string(65); var restoreval = string(seltechjobid); alert("thisval : " + thisval + " | typeof thisval : " + typeof thisval); alert("restoreval : " + restoreval + " | typeof restoreval : " + typeof restoreval); alert("thisval === restoreval : " + thisval === restoreval);

when run this, 3rd alert display "false". me should display "true". i'm missing something.

i've been googling hours , see of them type mismatch issue. can see, explicitly convert them both string shouldn't problem here.

by using: "thisval === restoreval : " + thisval concatening string, comparing "thisval === restoreval : 65" "65"

javascript json equality

No comments:

Post a Comment