How does the <or> operator work when comparing two lines?

I used <to compare two lines as follows:

console.log('ca'<'bb'); //false

I already know that it compares the number of Unicode characters. Because cno less b.

However, when I do this:

console.log('ba'<'bb');//true

It bothers me, because bno less than bit seems that he just missed it and compared the next character.

In any case, I wonder what rule is here when <or is >used to compare two lines and for some difficult situations, what if two lines have different lengths?

+4
source share
3 answers

, - , , . ( ):

. py px, false.

. px py, true.

. k - , , k px k py. ( ak, String .)

. m - , k px.

. n - , k py.

. m < n, true. false.

+3

, : , ..:

'ba'<'bb'

, a < b ( b )

'ca'<'bb'

, c b . (c > b)

0

a lexicographic.

It begins with the first letter and continues to inconsistency.

console.log ('cha' <'bb'); // false

It starts with c<b ? no. b<c? yes. -> c is 'greater' than b, therefore ca < bb -> false.

console.log ('ba' <'bb'); // true

It starts with b<b ? no. b > b? no. They both equal -> continue to next letter.
a < b ? yes. Therefore -> ba < bb -> true.

Wiki

0
source

Source: https://habr.com/ru/post/1543546/


All Articles