Last updated: Oct 20, 2021
Check out my new book
The "equalsIgnoreCase is not a function" error occurs because there isn't an
case, convert both of the strings to lowercase using the
and do a strict equality check.
Here is an example of how the error occurs.
const str1 = 'hello'; const str2 = 'HELLO'; // ⛔️ TypeError: equalsIgnoreCase is not a function const result = str1.equalsIgnoreCase(str2);
To solve the error, use the String.toLowerCase() method to convert both of the strings to lowercase before comparing them.
const str1 = 'hello'; const str2 = 'HELLO'; const result = str1.toLowerCase() === str2.toLowerCase(); console.log(result); // 👉️ true
We used the strict equality (===) operator, which returns a boolean result indicating whether the values to the left and right hand-side are equal and of the same type.
You could achieve the same result by converting both of the strings to uppercase using the String.toUpperCase() method before comparing them.
const str1 = 'hello'; const str2 = 'HELLO'; const result = str1.toUpperCase() === str2.toUpperCase(); console.log(result); // 👉️ true
You could also add a method named
equalsIgnoreCase on the prototype of the
String object, however this is discouraged because it is confusing for others
when reading your code.
If the strings contain any special characters, e.g. punctuation or digits, they
won't be affected by the