xxxxxxxxxx
var string1 = "Hello World";
var string2 = "Hello world.";
if (string1 === string2) {
console.log("Matching strings!");
}
else {
console.log("Strings do not match");
}
compare two strings
xxxxxxxxxx
string1.localeCompare(string2)
locaelCompare returns:
1 if string1 is greater (higher in the alphabetical order) than string2
-1 if string1 is smaller (lower in the alphabetical order) than string2
0 if string1 and string2 are equal in the alphabetical order
xxxxxxxxxx
const string1 = "abc";
const string2 = "def";
const result = string1.localeCompare(string2);
if (result === 0) {
console.log("The strings are equal.");
} else if (result < 0) {
console.log("String 1 comes before String 2.");
} else {
console.log("String 2 comes before String 1.");
}
xxxxxxxxxx
const string1 = "Hello";
const string2 = "World";
if (string1 === string2) {
console.log("The strings are equal.");
} else {
console.log("The strings are not equal.");
}
xxxxxxxxxx
const string1 = "Hello";
const string2 = "World";
if (string1 === string2) {
console.log("The strings are equal");
} else {
console.log("The strings are not equal");
}