comparison javascript code example
Example 1: javascript compare number to string
let string = "1";
let number = 1;
if (parseInt(string) === number){
}
if (string == number){
}
Example 2: string comparison in javascript
var str1 = "ab";
var str2 = "ab";
var n = str1.localeCompare(str2);
Example 3: javascript equality
18 === 18
18 === 19
`18` == 18
`18` === 18
`18` != 18
`18` !== 18
Example 4: equal to or more than javascript
a >= b
a <= b
Example 5: js comparison operators
Javascript Comparison Operators
== Equal to
=== Equal value and equal type
!= Not equal
!== Not equal value or not equal type
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
? Ternary operator