I am now working in javascript
string
sorting using localeCompare
and my data will contain several null
values too.
And i found a weird behavior with localeCompare
when comparing string
and null
value. When comparing string value upto startswith a/A to n/N
it working fine as below.
"n".localeCompare(null) // return -1;
"N".localeCompare(null) // return -1;
But after if i compare the null value with o/O to z/Z
it returns 1
"o".localeCompare(null) // return 1;
"O".localeCompare(null) // return 1;
I know that localeCompare
work with comparing Unicode
but why the above behavior happens is there any reason?