javascript

Check if a string is Palindrome or not using Javascript

The below function written in Javascript can be helpful to check whether a string is Palindrome or not.

function palindrome_checker(str) {
    const converted_str = str.split('').reverse().join('');
    if (str === converted_str) {
        console.log(str + " : String is Palindrome");
    } else {
        console.log(str + " : String is not Palindrome");
    }
}

palindrome_checker('deified');
palindrome_checker('Ankit');

What is a Palindrome String

If you reverse a string from right to left or left to right and it remains same then the string will be called Palindrome string. Civic is a palindrome string means if you read it left to right or right to left it will have same characters in same orders.

Live Demo

Was this helpful?