arr = ["1","2"]; $.each(arr,function(i,obj){ sum += parseint(obj); }); console.log(sum); i expect sum 3 result 12? thought parseint did job? what's wrong here?
the difference in behavior on how initializing sum
if var sum = 0; -> result expected i.e. 3 if var sum = ""; -> result 12 coming because sum string
Comments
Post a Comment