To compare two strings in JavaScript, you can use the ===
operator for strict equality or the ==
operator for loose equality.
In this example,
str1
and str2
with different values.===
operator for strict equality.===
operator returns true
if the strings are strictly equal, and false
otherwise.// Comparison of Strings in JavaScript using === operator
let str1 = 'Hello';
let str2 = 'hi';
let result = str1 === str2;
console.log('Strings are equal:', result);
Strings are equal: false
In this tutorial, we learned How to Compare Two Strings in JavaScript language with well detailed examples.