Javascript string/integer comparisons

后端 未结 8 1024
太阳男子
太阳男子 2020-11-22 16:34

I store some parameters client-side in HTML and then need to compare them as integers. Unfortunately I have come across a serious bug that I cannot explain. The bug seems to

8条回答
  •  自闭症患者
    2020-11-22 17:05

    Always remember when we compare two strings. the comparison happens on chacracter basis. so '2' > '12' is true because the comparison will happen as '2' > '1' and in alphabetical way '2' is always greater than '1' as unicode. SO it will comeout true. I hope this helps.

提交回复
热议问题