string compare js code example
Example 1: javascript compare number to string
let string = "1";
let number = 1;
if (parseInt(string) === number){
}
if (string == number){
}
Example 2: compare strings js
const s1 = 'learn';
const s2 = 'today';
console.log(s1 === 'learn');
console.log(s1 === s2);
Example 3: string comparison in javascript
var str1 = "ab";
var str2 = "ab";
var n = str1.localeCompare(str2);
Example 4: javascript compare strings
console.log(NaN===NaN);
Example 5: string comparison in javascript
console.log("10" == "10");
console.log(parseInt(10) == 10);