Prev Demo
JavaScript
>
Localecompare() Method
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <ul> <li>Returns "-1" if string A is sorted before string B.</li> <li>Returns "0" if string A and string B are equal.</li> <li>Returns "1" if string A is sorted after string B.</li> </ul> <p>Click the below button for comparing the two strings.</p> <input type="button" value="Compare" onclick="Function()" /> <p id="Id"></p> <script> function Function() { var A = "G H I J K L"; var B = "A B C D E F"; var r = A.localeCompare(B) document.getElementById("Id").innerHTML = r; } </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output