Cover image for Numerical Palindrome in JavaScript

Numerical Palindrome in JavaScript

coder4_life profile image coder4life ・1 min read

A palindrome is a word, number, or sequence of characters which reads the same backward as forward. In this coding challenge we need a solution that tells if a given number is a palindrome. Only numbers allowed. For example: 2442 or 100001.

function isPalindrome(num) {
    if (typeof num !== 'number' || num < 0) {
        return false;

    return +num.toString().split('').reverse().join('') === num;

console.log(isPalindrome(2442)); // true
console.log(isPalindrome(1234)); // false
console.log(isPalindrome(100001)); // true

Video going through this example:


Editor guide