Sometimes, we want to do JavaScript string or integer comparisons.
In this article, we’ll look at how to do JavaScript string or integer comparisons.
How to do JavaScript string or integer comparisons?
To do JavaScript string or integer comparisons, we convert everything to integers before we compare them.
For instance, we write
parseInt("2") > parseInt("10")
to convert the strings to integers with parseInt
before we compare them with >
.
Conclusion
To do JavaScript string or integer comparisons, we convert everything to integers before we compare them.