Js converts String to number for comparison

  • 2020-03-30 03:32:36
  • OfStack

Comparing strings without converting them is a headache

I didn't write it carefully, I didn't convert it, and I took it to a rough test,

1 < 2

Yeah, that's it


5.002 > 21.003

There are some weird results

In no conversion data type carried out > , < When determining, the system compares the values of the unicode encoding. What result is possible



Str1 * 1 > Str2 * 1

When comparing data in js, don't forget to convert the type!

Related articles: