how to compare two strings in javascript case insensitive code example

Example 1: Javascript case insensitive string comparison

var name1 = "Taylor Johnson";
var name2 ="taylor johnson";

//convert to lowercase for case insensitive comparison
if(name1.toLowerCase() === name2.toLowerCase()){
    //names are the same
}

Example 2: compare string camelcase and lowercase javascript

str.toUpperCase() === str || str.toLowerCase() === str;

Example 3: js ignore case

var str = "Visit W3Schools!";
var patt1 = /W3S/i;
var res = patt1.ignoreCase

Example 4: compare string camelcase and lowercase javascript

function sameCase(str) {
  return /^[A-Z]+$/.test(str) || /^[a-z]+$/.test(str);
}