Why does string to number comparison work in Javascript

前端 未结 3 1299
滥情空心
滥情空心 2020-11-22 14:30

I am trying to compare a value coming from a HTML text field with integers. And it works as expected. Condition is -

x >= 1 && x <= 999;
         


        
3条回答
  •  难免孤独
    2020-11-22 15:19

    You should use parseInt if the var is a string. Add = to compare datatype value:

    parseInt(x) >== 1 && parseInt(x) <== 999;
    

提交回复
热议问题