What is a palindrome?
Palindrome is a word or phrase which reads same if reversed.
For example – if we reverse Racecar it will read the same both backward or forwards. A few examples of words that are palindrome are Noon, Racecar, Wow, Refer, etc.
function strPalindrome(str) {
let newstr = str.split("").reverse().join("");
if (newstr === str) {
return "Yes it is a palindrome.";
} else {
return "No it is not a palindrome.";
}
}
console.log(strPalindrome("racecar")); //Yes it is a palindrome.
console.log(strPalindrome("welcome")); //No it is not a palindrome.