A palindrome number reads the same forwards and backwards. Classic examples: 121, 3443, and every one-digit value.
Remember
n is palindrome ↔ reverse(digits of n) == n
Examples:
121 → reverse 121 → yes
123 → reverse 321 → no
7 → reverse 7 → yes
10 → reverse 01=1 → no
n
Reverse
Palindrome?
121
121
Yes
1221
1221
Yes
123
321
No
Approach
How to Check a Palindrome Number in JavaScript
Four clear steps — then pick a math reverse or a string compare.
Reject negatives for this beginner rule (optional: work with Math.abs if your problem allows it).
Copy n into a temporary variable.
Build the reverse: repeatedly take digit = temp % 10, then rev = rev * 10 + digit, then temp = Math.floor(temp / 10).
Compare rev with the original n.
Method
Idea
Time
Best for
Digit reverse
Build rev with % 10 / Math.floor
O(d)
Interviews (no string help)
String compare
Compare text with its reverse
O(d)
Quick, readable code
Range scan
Reuse the helper for each value
O(N d)
Listing palindromes
Pseudocode
Pseudocode
function IsPalindrome(n):
if n < 0:
return false
original = n
rev = 0
while n > 0:
digit = n mod 10
rev = rev * 10 + digit
n = n / 10
return rev == original
Reference
Cheat Sheet
Keep these facts handy while writing the program.
Topic
Detail
Core idea
Reverse digits, then compare
Digit peel
n % 10 then Math.floor(n / 10)
Build reverse
rev = rev * 10 + digit
One digit
Always palindrome
Negatives
Usually not (this page: false)
Classic checks
121 yes; 123 no; 10 no
Try it
Live Preview
Enter an integer to see the reversed digits and the palindrome check.
Whole numbers only. Negatives count as not palindrome here. Tap a chip or type a value.
Result
n = 121
Reverse = 121
121 is a palindrome
Code
JavaScript Programs
Start with the math reverse — interviewers usually want that. Then list palindromes in a range, and finish with a string compare. Each example has a Try it Yourself editor.
Example 1 — Digit Reverse
Build the reverse integer with remainder and integer division, then compare.
JavaScript
function isPalindrome(n) {
if (n < 0) {
return false;
}
const original = n;
let rev = 0;
while (n > 0) {
const digit = n % 10;
rev = rev * 10 + digit;
n = Math.floor(n / 10);
}
return rev === original;
}
const number = 121;
if (isPalindrome(number)) {
console.log(number + " is a palindrome");
} else {
console.log(number + " is not a palindrome");
}
Negatives return false immediately under this page’s rule.
Save original because the loop will destroy the working copy of n.
Each step peels the last digit with n % 10 and appends it to rev.
Math.floor(n / 10) drops that digit so the loop moves leftward.
When the loop ends, rev === original means the digits matched both ways.
Example 2 — Palindromes from 100 to 200
Reuse the helper to print every palindrome in a small band.
JavaScript
function isPalindrome(n) {
if (n < 0) {
return false;
}
const original = n;
let rev = 0;
while (n > 0) {
rev = rev * 10 + (n % 10);
n = Math.floor(n / 10);
}
return rev === original;
}
console.log("Palindrome numbers from 100 to 200:");
let line = "";
for (let i = 100; i <= 200; i++) {
if (isPalindrome(i)) {
line += i + " ";
}
}
console.log(line.trim());