JavaScript Program to check a number is palindrome or not

In this program, You will learn how to check a number is palindrome or not in JavaScript.


while(condition){
    //statement
    //Increment/Decrement
}

JavaScript Program to check a number is palindrome or not

Example: How to check a number is palindrome or not in JavaScript

let num = n = parseInt(prompt("Enter a number"))
let rev = 0, r;

rev = 0;
while (n > 0) {
  r = n % 10;
  rev = rev * 10 + r;
  n = parseInt(n / 10)
}

if (num == rev) {
  console.log("Number is palindrome:" + num)
} else {
  console.log("Number is not palindrome:" + num)
}

Output:

Enter a number> 121
Number is palindrome:121