A palindrome is a word, phrase, number or sequence of words that reads the same backward as forward.
Example :
//Using inbuilt functions function checkPalindrome(str) { let reversedStr=str.split("").reverse().join(""); if(str===reverseStr) { return "It is a palindrome"; } return "It is not a palindrome"; } console.log(checkPalindrome("madam")); //Prints: It is a palindrome console.log(checPalindrome("hello")); //Prints: It is not a palindrome
///Without using inbuilt functions function checkPalindrome(str) { const len = str.length; for (let i = 0; i < len / 2; i++) { if (str[i] !== str[len - 1 - i]) { return "It is not a palindrome"; } } return "It is a palindrome";} console.log(checkPalindrome("madam")); //Prints: It is a palindrome console.log(checPalindrome("hello")); //Prints: It is not a palindrome