JavaScript program to compare two strings are equal by ignoring the case
Following program shows you how to compare two strings are equal by ignoring the case.
In this program we get two different cases of strings from user and shows those strings are equal by using .toLocaleLowerCase()
var string1 = prompt("Please enter string1:");
var string2 = prompt("Please enter string2:");
if (string1.toLocaleLowerCase(string2)) {
console.log("Given strings are equal");
} else {
console.log("Given strings are not equal");
}
Output:
Example1:
Please enter string1:
HELLO
Please enter string2:
hello
Given strings are equal
Example2:
Please enter string1:
hello
Please enter string2:
world
Given strings are not equal