string equality in javascript code example
Example 1: string comparison in javascript
var str1 = "ab";
var str2 = "ab";
var n = str1.localeCompare(str2);
Example 2: javascript equality
18 === 18 // true
18 === 19 // false
`18` == 18 // true
`18` === 18 // false
// == : loose equality operator (date type IS NOT relevant)
// === : strict equality operator (date type IS relevant)
// Note: the same applies for not equal
`18` != 18 // false
`18` !== 18 // true
Example 3: string comparison in javascript
console.log("10" == "10"); //True
console.log(parseInt(10) == 10); // True Best practice