Practicing functions and the Strict Equals in my conditional is acting wrong and I am not sure why

I am new to coding and I am just practicing with some functions and I came across something with the "strict equal" of my conditional.

I am building a simple palindromeChecker in JS.

so I made this:

const w = "Apple";

const palindromeChecker = (phrase) => {
  const lowerWord = phrase.toLowerCase().split(" ").join("").split("");
  console.log("LowerWord: --->", lowerWord);
  const result = lowerWord.join("")
  console.log("Result: --->", result);
  const reverse = lowerWord.reverse().join("");
  console.log("Reverse: --->", reverse);

  if (lowerWord.join("") === reverse) {
    return true
  } else {
    return false
  }
};

console.log(palindromeChecker(w));

the return keeps coming back true even though the word is clearly not a palindrome. I'm know that I can exchange:

lowerWord.join("")

in the conditional with:

result

and I get the correct answer, but I am wondering why I am getting "true" with lowerWord.join("") when the string is not the same?

thanks in advance!



Read more here: https://stackoverflow.com/questions/68460662/practicing-functions-and-the-strict-equals-in-my-conditional-is-acting-wrong-and

Content Attribution

This content was originally published by Overseer009 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: