string comparison in javascript code example

Example 1: javascript compare number to string

let string = "1";
let number = 1;
if (parseInt(string) === number){
  	// STRING AND NUMBER MATCHES
}
if (string == number){
  // STRING AND NUMBER MATCHES ALSO BECAUSE == instead of ===, means it won't compare datasets, only the content
}

Example 2: string comparison in javascript

var str1 = "ab";
var str2 = "ab";
var n = str1.localeCompare(str2);

Example 3: javascript compare strings

console.log(NaN===NaN);//false

Example 4: string comparison in javascript

console.log("10" == "10"); //True
console.log(parseInt(10) == 10); // True Best practice