Anjan Dutta
How to test string palindrome in JavaScript
How to test string palindrome in JavaScript
Created On: 02/10/2021
To test if a string is a palindrome or not, we can use several methods in javascript.
In the below example, we will reverse the string first and then compare both the original string and the reversed string. If both are the same then the string is a palindrome. See below code.
function checkPalindrom( text) { return text === text.split('').reverse().join('');}
let text = "Hello World"console.log(checkPalindrom(text));// false
text = "madam"console.log(checkPalindrom(text));// true