JavaScript Number preserve leading 0

前端 未结 3 804
盖世英雄少女心
盖世英雄少女心 2020-12-02 02:53

I have a problem, I build a very simple javascript search for postal codes. I am using JS Numbers because I want to check if the passed number (search term) is less||equal o

3条回答
  •  独厮守ぢ
    2020-12-02 03:15

    Instead a parseInt you could use type casting :)

    "0123">"122" // false
    +"0123">"122" // true  | that  means: 123>"122" 
    

    Btw, what more you can use a each of bitwise operators :

     ~~"0123"   
     "0123"|0  
     "0123"&"0123" 
     "0123">>0
     "0123"<<0 
    

    With the same effect :)

提交回复
热议问题