Compare two strings in the current locale:
The result of n will be:
More "Try it Yourself" examples below.
The localeCompare() method compares two strings in the current locale.
The locale is based on the language settings of the browser.
The localeCompare() method returns a number indicating whether the string comes before, after or is equal as the compareString in sort order.
Method | |||||
---|---|---|---|---|---|
localeCompare() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
compareString | Required. The string to compare with |
Return Value: | A Number, indicating whether the reference string comes before, after or
is the same as the compareString in sort order.
Returns one of three values:
|
---|---|
JavaScript Version: | 1.2 |
Compare two strings in the current locale:
The result of n will be:
Compare two equal strings in the current locale:
The result of n will be: