To reverse a number, peel digits off the end and push them onto a new number:
let rev = 0;
while (n > 0) {
rev = rev * 10 + (n % 10);
n = Math.floor(n / 10);
}
Multiplying rev by 10 shifts its digits left to make room for the new digit. Leading zeros vanish on their own: reversing 1200 gives 21.