compare string 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: compare strings js

const s1 = 'learn';
const s2 = 'today';

console.log(s1 === 'learn');  // true
console.log(s1 === s2);       // false

Example 3: string comparison in javascript

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

Example 4: != javascript

// " != " in Javasacript means : not equal.

Example 5: equal to or more than javascript

//Equal to or more than
a >= b
//Equal to or less than
a <= b

Example 6: javascript compare strings

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