

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to do case insensitive string comparison of strings in JavaScript
We are required to write a JavaScript function that takes in two strings as arguments. The function should check for equality of both the strings ignoring their case.
For example −
areEqual('done', 'DOne') should return true.
Example
The code for this will be −
const str1 = 'done'; const str2 = 'DOne'; const caseSensitiveCheck = (str1 = '', str2 = '') => { const loweCase1 = str1.toLowerCase(); const loweCase2 = str2.toLowerCase(); return loweCase1 === loweCase2; }; console.log(caseSensitiveCheck(str1, str2));
Output
And the output in the console will be −
true
- Related Questions & Answers
- How do I make my string comparison case insensitive?
- How do I do a case insensitive string comparison in Python?
- Case-insensitive string comparison in C++
- How do we make my string comparison case insensitive in java?
- How to do case-sensitive string comparison in JavaScript?
- JavaScript filter an array of strings, matching case insensitive substring?
- How to use case-insensitive switch-case in JavaScript?
- JavaScript Count characters case insensitive
- How do I make case-insensitive queries on MongoDB?
- Case sensitive string comparison in Java.
- JavaScript Check for case insensitive values?
- How to perform Case Insensitive matching with JavaScript RegExp?
- How MySQL can perform case-sensitive string comparison?
- How to make SQL case sensitive string comparison in MySQL?
- How to compare two string arrays, case insensitive and independent about ordering JavaScript, ES6
Advertisements