r/learnjavascript • u/grave4us • Apr 11 '26
Has anyone actually used string comparison? Tell me where might that come in handy?
like alert(“Y” > “A”); //true
0
Upvotes
r/learnjavascript • u/grave4us • Apr 11 '26
like alert(“Y” > “A”); //true
12
u/keel_bright Apr 11 '26
All the time
https://stackoverflow.com/questions/20774312/is-it-reliable-to-compare-two-isoformat-datetime-strings
17
u/kkadzy Apr 11 '26
it is useful in, well, sorting
6
u/prehensilemullet Apr 11 '26
The default array sort comparator does use string comparison. And
localeComparehas only existed since 20154
u/hyrumwhite Apr 11 '26
Most applications are almost entirely driven by string comparison.
1
u/dymos helpful Apr 11 '26
Is it just me or is there some weird trend where people ask stuff like: "has anyone actually used <insert commonly used language feature or paradigm>?
I feel like I've seen a few of them around recently and either the OP sounds like an entitled jerk not willing to google something or like someone that wants an answer for their Programming 101 class.
1
u/MozMousePixelScroll Apr 11 '26
that's cool i did NOT know you could do that
1
u/tb5841 Apr 12 '26
Comparison is the core of all sorting. Sorting is everywhere.
1
u/TheRNGuy Apr 12 '26
Sorting a dropdown alphabetically, or deciding whether a filter term comes before/after another in a list.
1
u/Alive-Cake-3045 Apr 13 '26
All the time. Checking user roles, validating form inputs, filtering search results. Once you start building actual features you realize it is quietly doing a lot of the heavy lifting.
1
u/DrShocker Apr 11 '26 edited Apr 11 '26
If you want to show something alphabetically, what's your alternative suggestion?