LocaleCompare-3

 

JavaScript localeCompare function will return 

  • -1 if the string1 is sorted before the string2
  • 0 if the two strings are equal
  • 1 if the reference string1 is sorted after the string2


 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <script> var str1 = new String( "This is beautiful string" ); var index = str1.localeCompare( "XYZ" ); document.write("localeCompare first :" + index ); document.write("<br />" ); var index = str1.localeCompare( "AbCD ?" ); document.write("localeCompare second :" + index ); </script> </body> </html>
Output