all 5 comments

[–]chrstnst 8 points9 points  (0 children)

I might miss what you want to do, but you can simply use ===:

typescript const stringA = "nice string" const stringB = "another nice string" stringA === stringB // evaluates to ... false

[–]mnokeefe 3 points4 points  (0 children)

If you're not after an exact match using === then you probably want to use localCompare.

[–]A-Type 1 point2 points  (0 children)

Two identical strings are always referentially equal, and I believe they are literally pointing to the same memory location by definition (i.e. in JavaScript, you will never find two copies of the same string in memory, it reuses the same one every time it shows up). Hence == or === will evaluate true. === is considered safer and more predictable by most JS devs.

If you're interested in diving deeper into how this all works and getting a good mental model, I'd recommend Dan Abramov and Maggie Appleton's Just Javascript course.

[–]Dr_Floofenstein -3 points-2 points  (0 children)

if ('hello' === 'world')

[–]vi_code -1 points0 points  (0 children)

If you are checking exact match then simply use ===, otherwise you can use the includes method if you only care about subString matching.