Can you use these comparison operators on data types other than numbers?


#1

Question

Can you use these comparison operators on data types other than numbers?

Answer

Yes you can, although I would recommend that you don’t do this unless you are using it intentionally for a specific purpose as things might get tricky. For strings, the comparison operator checks to see which word starts with a lesser/greater value. Essentially it’s alphabetized and you can think of it like trying to see which of the strings you’d find first in a dictionary going from start to finish, the first one you see will have a lower value. Example: 'apple' < 'orange' will evaluate to true.