//The way to convert STR to digital, think of a long time ago a face test, say the way the character to the number, and now think aboutvarStr1= ' 4.88 ', str2= ' 4.8xx '; Console.log (parseint (str1))//4Console.log (str1|0)//4Console.log (str1-0)//4.88Console.log (+STR1)//4.88Console.log (-(-STR1))//4.88Console.log (~~STR1)//4Console.log (str1<<0)//4Console.log (str1>>0)//4Console.log (number (STR1))//4.88Console.log (parseint (str2))//4Console.log (str2|0)//0Console.log (str2-0)//NaNConsole.log (+STR2)//NaNConsole.log (-(-STR2))//NaNConsole.log (~~STR2)//0Console.log (str2<<0)//0Console.log (str2>>0)//0Console.log (number (STR2))//NaN//The str2 conversion may fail, the number, Pasreint, and the value are Nan, and the bitwise operation Gets the 0;-0 And number will get its true type, integer or floating-point type. And all the other direct get is the integral type//but I usually use xxx|0 XXX-0 .
JavaScript string to Number