Sometimes, we want to compare two variables containing strings in JavaScript.
In this article, we’ll look at how to compare two variables containing strings in JavaScript.
How to compare two variables containing strings in JavaScript?
To compare two variables containing strings in JavaScript, we can use the ===
operator.
For instance, we write:
const a = 'foo'
const b = 'foo'
console.log(a === b)
to compare strings a
and b
with ===
to check if they’re equal.
Therefore, the console log logs true
since they’re the same.
Conclusion
To compare two variables containing strings in JavaScript, we can use the ===
operator.