> For the complete documentation index, see [llms.txt](https://javascriptuse.gitbook.io/advanced/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://javascriptuse.gitbook.io/advanced/localecompare-method-compares-two-strings-return-sort-order-1-1-0-for-before-after-or-equal.md).

# localeCompare() method compares two strings return sort order -1, 1,0 (for before, after, or equal)

https\://www\.w3schools.com/Jsref/jsref\_localecompare.asp

```html
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Strings</h1>
<h2>The localeCompare() Method</h2>
<p>localeCompare() returns one of 3 numbers indicating the sort order.</p> 
<ul>
  <li>-1 if sorted before</li>
  <li>1 if sorted after</li>
  <li>0 if equal</li> 
</ul>
<p>Compare "cd" with "ab":</p>
<p id="demo"></p>
<script>
let text1 = "cd";
let text2 = "ab";
let result = text1.localeCompare(text2);
document.getElementById("demo").innerHTML = result;
</script>
</body>
</html>
JavaScript Strings
The localeCompare() Method
localeCompare() returns one of 3 numbers indicating the sort order.
-1 if sorted before
1 if sorted after
0 if equal
Compare "cd" with "ab": 1
```
