Intermediate Algorithm Scripting: Search and Replace 2

How does one compare the cases of letters? I don’t know how to express it in the ‘before.charAt(0) === after.charAt(0)’ part. I know it is only comparing the letters right now.

function myReplace(str, before, after) {
  var newStr = ''; 
  var arr = str.split(' ');
  var afterNew = after.replace(after.charAt(0),after.charAt(0).toUpperCase());
  if (before.charAt(0) === after.charAt(0)) {
    newStr = str.replace(before, afterNew);
  } else {
    newStr = str.replace(before, after);
  return newStr;

myReplace("Let us go to the store", "store", "mall");

Link to the challenge:

If I wanted to know if a character was upper case, I would do something like the following:

var someChar = 'h';
var anotherChar = 'D';
var isSomeCharUpperCase = someChar === someChar.toUpperCase(); // false
var isAnotherCharUpperCase = anotherChar === anotherChar.toUpperCase(); // true

Thanks, that worked perfectly. Didn’t think of doing it that way.