1

Hii All,

"Aardvark" < "Zoroaster"  # return "true"

I think, this is very basic. But I can't understand above statement which is collected one of the js article.

Shall u explained them.

2 Answers 2

2

You can compare strings using the equality, greater-than and less-than operators.

Using either greater-than or less-than will perform a dictionary style comparison, ie which comes first in the dictionary?

Sign up to request clarification or add additional context in comments.

4 Comments

Phil, "dictionary style comparison" means, each character assign ascii ? Shall u explain "dictionary style comparison"
But dictionaries are usually sorted without regard for case, noting that of course the vast majority of words in the dictionary are all lowercase - are you saying that the JS greater-than and less-than operators are also case insensitive when used on strings?
@nnnnnn It looks like uppercase is considered lower than lowercase, ie "a" > "A"
Yeah, I believe the comparison is based on the Unicode character order.
1

This basically means that in JS "Aardvark" is considered lesser than "Zoroaster" because JS uses something called Lexicographical Ordering, also known as Dictionary Order because dictionaries also use the same order when listing words.

1 Comment

The JS greater-than and less-than operators do not sort in dictionary order unless you convert both strings to lowercase (or both to upper) before hand. If you have mixed case then "abc" < "bcd" but "abc" > "Bcd".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.