How palindrome checking actually works
A palindrome reads the same forwards and backwards. The standard algorithm: normalize the string (lowercase, strip non-alphanumeric), then compare the string to its reverse. In JavaScript: s.toLowerCase().replace(/[^a-z0-9]/g, '') === […].reverse().join(''). This is O(n) time and O(n) space. The two-pointer approach (compare characters from both ends moving inward) uses O(1) space if you normalize first.
Classic examples: "racecar", "A man a plan a canal Panama", "Was it a car or a cat I saw". The normalization step is why these work — without stripping spaces and punctuation, "A man..." would fail a naïve check.
Unicode characters that trip up naive implementations
JavaScript strings are UTF-16. Emoji and characters above U+FFFF (like many Chinese characters and math symbols) are stored as two code units called a surrogate pair. .split('').reverse().join('') splits on code units, not characters — it breaks surrogate pairs and produces garbage for any string containing emoji or extended Unicode.
The fix: use the spread operator [...str].reverse().join('') which iterates over Unicode code points correctly, or use Intl.Segmenter for languages with combining characters (Arabic, Thai, Hindi) where a single "user-visible character" may be multiple code points. This checker handles the common cases; for production text processing that must be Unicode-correct, use a dedicated library.
50 famous palindrome examples — words, phrases & numbers
Single words (25)
| Word | Length |
|---|---|
| racecar | 7 chars |
| level | 5 chars |
| civic | 5 chars |
| radar | 5 chars |
| noon | 4 chars |
| madam | 5 chars |
| kayak | 5 chars |
| rotator | 7 chars |
| repaper | 7 chars |
| deified | 7 chars |
| reviver | 7 chars |
| refer | 5 chars |
| tenet | 5 chars |
| rotor | 5 chars |
| deed | 4 chars |
| peep | 4 chars |
| pup | 3 chars |
| nun | 3 chars |
| eye | 3 chars |
| aha | 3 chars |
| wow | 3 chars |
| gag | 3 chars |
| did | 3 chars |
| bib | 3 chars |
Famous phrases (15)
A man a plan a canal Panama
Was it a car or a cat I saw
Never odd or even
Do geese see God
Step on no pets
No lemon no melon
Mr Owl ate my metal worm
Eva can I see bees in a cave
Was it a rat I saw
Madam Im Adam
A Toyota race car a Toyota
Rise to vote sir
Murder for a jar of red rum
Rats live on no evil star
A Santa at NASA
Numbers (10)
| Number | Digits |
|---|---|
| 11 | 2 digits |
| 121 | 3 digits |
| 1001 | 4 digits |
| 10101 | 5 digits |
| 12321 | 5 digits |
| 1234321 | 7 digits |
| 99999 | 5 digits |
| 1221 | 4 digits |
| 9009 | 4 digits |
| 123454321 | 9 digits |
