About 107,000 results
Open links in new tab
  1. What is the correct way to check for string equality in JavaScript ...

    Aug 27, 2010 · However, note that string objects will not be equal. new String("a") == new String("a") will return false. Call the valueOf() method to convert it to a primitive for String …

  2. Optimum way to compare strings in JavaScript? - Stack Overflow

    Unfortunately, stringCompare is not reliable. Opera, IE, Firefox, Chrome and Safari all return 1 for 'dog'.localeCompare('cat'), which is to be expected, and -1 when you reverse the caller and …

  3. Which equals operator (== vs ===) should be used in JavaScript ...

    Dec 11, 2008 · With other words, if String wouldn't be of type Object it couldn't be used with the new operator. new always returns an Object, even for String constructors, too. And alas! The …

  4. What is the fastest way to compare strings in JavaScript?

    Comparing strings with a === b is the fastest way to compare string natives. However, if you could create String Objects like new String("test"), re-use those and use those in the comparisons, …

  5. Is JavaScript string comparison just as fast as number comparison ...

    The flaw in the tests mentioned in the question is the fact that we are testing against literal strings. It seems that JavaScript is optimized so that string comparison for string literals is done just by …

  6. How to do case insensitive string comparison? - Stack Overflow

    Jan 26, 2010 · Use RegEx for string match or comparison. In JavaScript, you can use match() for string comparison, don't forget to put i in the regular expression. This flag will force case …

  7. how to compare two strings in javascript if condition

    Feb 18, 2017 · javascript; if-statement; string-comparison; Share. Improve this question. Follow edited Mar 6, 2020 at 18 ...

  8. Why is one string greater than the other when comparing strings …

    The comparison of Strings uses a simple lexicographic ordering on sequences of code unit values. And this if both operands are strings: If Type(px) is String and Type(py) is String, then …

  9. html - Javascript string/integer comparisons - Stack Overflow

    Aug 29, 2022 · Yes it gets a boolean from the < result and coerces it to string, but by then it's too late to affect how the comparison worked. JS < operator behavior depends on its two …

  10. javascript - comparing 2 strings alphabetically for sorting purposes ...

    Apr 17, 2012 · JavaScript compares strings character by character and "a" comes before "b" in the alphabet - hence less than. In your case it works like so - 1 . " a aaa" < " a b"

Refresh