js string comparison code example
Example 1: string comparison in javascript
var str1 = "ab";
var str2 = "ab";
var n = str1.localeCompare(str2);
Example 2: how to compare two strings in javascript if condition
var string1 = "Hello World";
var string2 = "Hello world.";
if (string1 === string2) {
console.log("Matching strings!");
}
else {
console.log("Strings do not match");
}
Example 3: string comparison in javascript
console.log("10" == "10"); //True
console.log(parseInt(10) == 10); // True Best practice