Low-level integer numbers reversing:

function flipInt(n){
    var digit, result = 0

    while( n ){
        digit = n % 10  //  Get right-most digit. Ex. 123/10 β†’ 12.3 β†’ 3
        result = (result * 10) + digit  //  Ex. 123 β†’ 1230 + 4 β†’ 1234
        n = n/10|0  //  Remove right-most digit. Ex. 123 β†’ 12.3 β†’ 12
    }  
  
    return result
}


// Usage: 
alert(
  "Reversed number: " + flipInt( +prompt("Enter a value") ) 
)
Run code snippetEdit code snippet Hide Results Copy to answer Expand

The above code uses bitwise operators for quick math

This method is MUCH FASTER than other methods which convert the number to an Array and then reverse it and join it again. This is a low-level blazing-fast solution.

Illustration table:

Show code snippet

const delay = (ms = 1000) => new Promise(res => setTimeout(res, ms))
const table = document.querySelector('tbody')

async function printLine(s1, s2, op){
  table.innerHTML += `<tr>
    <td>{s2||''}</td>
  </tr>`
}

async function steps(){
  printLine(123)
  await delay()
  
  printLine('12.3 β†’')
  await delay()
  
  printLine(12, 3)
  await delay()
  
  printLine('1.2', '3 &times; 10')
  await delay()
  
  printLine('1.2 β†’', 30)
  await delay()
  
  printLine(1, 32)
  await delay()
  
  printLine(1, '32 &times; 10')
  await delay()
  
  printLine('1 β†’', 320)
  await delay()
  
  printLine('', 321)
  await delay()
}

steps()
table{ width: 200px; }
td {
  border: 1px dotted #999;
}
<table>
  <thead>
    <tr>
      <th>Current</th>
      <th>Output</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Answer from vsync on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί javascript β€Ί javascript-program-to-reverse-digits-of-a-number
JavaScript Program to Reverse Digits of a Number - GeeksforGeeks
July 23, 2025 - There are several methods that ... In this approach, we are using string reversal, converting a number to a string, reverse it using split('').reverse().join(''), and convert back to a number....
🌐
Scaler
scaler.com β€Ί home β€Ί topics β€Ί reverse a number in javascript
Reverse a Number in JavaScript - Scaler Topics
May 29, 2024 - We can convert the number to a string value, split the string value, and put all of the string's characters in an array, then, reverse the array and finally convert that array to a string by connecting all characters, and then finally convert that string back to a number. In JavaScript, this approach can be completed in only one line using the below 3 functions:
People also ask

What is the easiest way to reverse a number in JavaScript?
The easiest way to reverse a number in JavaScript is to convert it to a string, then use built-in functions like split(), reverse(), and join() to flip the digits.
🌐
wscubetech.com
wscubetech.com β€Ί resources β€Ί javascript β€Ί programs β€Ί reverse-number
Reverse a Number in JavaScript (7 Programs)
Can I use recursion to reverse a number in JavaScript?
Yes, you can use recursion to reverse a number in JavaScript by taking the last digit, calling the function again with the remaining digits, and combining them to build the reversed number.
🌐
wscubetech.com
wscubetech.com β€Ί resources β€Ί javascript β€Ί programs β€Ί reverse-number
Reverse a Number in JavaScript (7 Programs)
How to reverse a number in JavaScript using a for loop?
To reverse a number using a for loop, convert it to a string and loop from the last digit to the first, adding each digit to a new string, then convert it back to a number.
🌐
wscubetech.com
wscubetech.com β€Ί resources β€Ί javascript β€Ί programs β€Ί reverse-number
Reverse a Number in JavaScript (7 Programs)
Top answer
1 of 16
48

Low-level integer numbers reversing:

function flipInt(n){
    var digit, result = 0

    while( n ){
        digit = n % 10  //  Get right-most digit. Ex. 123/10 β†’ 12.3 β†’ 3
        result = (result * 10) + digit  //  Ex. 123 β†’ 1230 + 4 β†’ 1234
        n = n/10|0  //  Remove right-most digit. Ex. 123 β†’ 12.3 β†’ 12
    }  
  
    return result
}


// Usage: 
alert(
  "Reversed number: " + flipInt( +prompt("Enter a value") ) 
)
Run code snippetEdit code snippet Hide Results Copy to answer Expand

The above code uses bitwise operators for quick math

This method is MUCH FASTER than other methods which convert the number to an Array and then reverse it and join it again. This is a low-level blazing-fast solution.

Illustration table:

Show code snippet

const delay = (ms = 1000) => new Promise(res => setTimeout(res, ms))
const table = document.querySelector('tbody')

async function printLine(s1, s2, op){
  table.innerHTML += `<tr>
    <td>{s2||''}</td>
  </tr>`
}

async function steps(){
  printLine(123)
  await delay()
  
  printLine('12.3 β†’')
  await delay()
  
  printLine(12, 3)
  await delay()
  
  printLine('1.2', '3 &times; 10')
  await delay()
  
  printLine('1.2 β†’', 30)
  await delay()
  
  printLine(1, 32)
  await delay()
  
  printLine(1, '32 &times; 10')
  await delay()
  
  printLine('1 β†’', 320)
  await delay()
  
  printLine('', 321)
  await delay()
}

steps()
table{ width: 200px; }
td {
  border: 1px dotted #999;
}
<table>
  <thead>
    <tr>
      <th>Current</th>
      <th>Output</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>
Run code snippetEdit code snippet Hide Results Copy to answer Expand

2 of 16
11

Assuming @DominicTobias is correct, you can use this:

console.log( 
    +prompt("Enter a value").split("").reverse().join("") 
)
Run code snippetEdit code snippet Hide Results Copy to answer Expand

🌐
freeCodeCamp
freecodecamp.org β€Ί news β€Ί js-basics-how-to-reverse-a-number-9aefc20afa8d
How to reverse a number in JavaScript
February 3, 2019 - Negative numbers should remain negative. ... Any leading zeroes should be removed. ... The function can accept floats or integers. ... The function will return integers as integers. ... function reversedNum(num) { return ( parseFloat( num .toString() .split('') .reverse() .join('') ) * Math.sign(num) ) }
🌐
W3Resource
w3resource.com β€Ί javascript-exercises β€Ί javascript-function-exercise-1.php
JavaScript function: Reverse a number - w3resource
The reversed_num variable is used to store the reversed number, which is initially set to 0. The while loop continues until num is 0, at which point the reversed number is returned. ... See the Pen javascript-function-exercise-1-1 by w3resource (@w3resource) on CodePen.
🌐
CodeVsColor
codevscolor.com β€Ί how to reverse a number in javascript - codevscolor
How to reverse a number in JavaScript - CodeVsColor
April 8, 2023 - Number reverse programs in different programming languages uses similar algorithms. We will discuss different ways to reverse a number in this post. You will learn how to use a while loop, how to use the modulo operation, and how to find the floor value of a number in JavaScript with these examples.
Find elsewhere
🌐
Just Academy
justacademy.co β€Ί blog-detail β€Ί how-to-reverse-a-number-in-javascript
How to Reverse a Number in JavaScript by Roshan Chaturvedi | JustAcademy
Implementing a function to reverse a number in JavaScript involves iterating through the digits of the number and reconstructing them in reverse order, typically utilizing basic math operations like modulo (%) and division (/) to extract and ...
🌐
Juneikerc
juneikerc.com β€Ί en β€Ί code-blog β€Ί javascript β€Ί reverse-number
How to Reverse a Number in JavaScript? [Easy]
February 18, 2024 - In this tutorial, you will learn to reverse a number in js, for example, changing 123456789 to 987654321 in a very simple way.
🌐
WsCube Tech
wscubetech.com β€Ί resources β€Ί javascript β€Ί programs β€Ί reverse-number
Reverse a Number in JavaScript (7 Programs)
October 30, 2025 - Discover 7 different ways to reverse a number in JavaScript with easy-to-follow examples and output. Ideal for beginners to learn number manipulation step by step.
🌐
TecAdmin
tecadmin.net β€Ί javascript-code-to-reverse-a-number
JavaScript Code to Reverse a Number – TecAdmin
April 26, 2025 - In this code, we use a ternary operator to check if the original number was negative. If it was, we return the reversed number as a negative number. Otherwise, we return it as a positive number. In summary, JavaScript provides several powerful tools and methods for working with numbers and strings.
🌐
LabEx
labex.io β€Ί tutorials β€Ί javascript-reversing-numbers-in-javascript-28599
Reverse Numbers in JavaScript | LabEx
Preserve the sign of the number using Math.sign(). ... reverseNumber(981); // 189 reverseNumber(-500); // -5 reverseNumber(73.6); // 6.37 reverseNumber(-5.23); // -32.5
🌐
EDUCBA
educba.com β€Ί home β€Ί software development β€Ί software development tutorials β€Ί javascript tutorial β€Ί reverse in javascript
Reverse in JavaScript | Logic to find out reverse in JavaScript with example
March 17, 2023 - The point to be noted here is that the parseFloat function runs in the end on the reversed number and removes any leading zeroes (even though it is on the first line of the function). The number * Math.sign(number) helps multiply a number with the preceding sign of the original input given. <script language='javascript'> Reverse = function(num) { var reversed_number = 0; while (num != 0) { reversed_number *= 10; reversed_number += number % 10; num -= num % 10; num /= 10; } return reversed_number; } </script> <body> <input type= 'text' id='string'/>&nbsp;<input type='button' value='text' onclick='alert("reversed = " +Reverse(document.getElementById("string").value);'/> </body>
Call Β  +917738666252
Address Β  Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
CodeProject
codeproject.com β€Ί Tips β€Ί 1120810 β€Ί How-to-Reverse-a-Number-using-JavaScript
How to Reverse a Number using JavaScript
General Programming - Free source code and tutorials for Software developers and Architects.; Updated: 17 Mar 2023
🌐
TutorialsPoint
tutorialspoint.com β€Ί reverse-a-number-in-javascript
Reverse a number in JavaScript
August 18, 2020 - const num = 124323; const reverse = (num) => parseInt(String(num) .split("") .reverse() .join(""), 10); console.log(reverse(num));
🌐
Studyfame
studyfame.com β€Ί javascript-program β€Ί javascript-reverse-number
JavaScript Reverse Number
<!DOCTYPE html> <html> <body> <script> function reverse() { var r,rev=0,n; n = parseInt(prompt("enter a number:")); do{ r = n % 10; rev = rev * 10 + r; n = parseInt(n / 10); }while(n != 0); document.write("reverse of number is:"+rev); } </script> <form> <input type="button" value="reverse" onclick="reverse();" /> ...
🌐
Sitesbay
sitesbay.com β€Ί js-program β€Ί javascript-reverse-a-number-program-in-javascript
Reverse a Number Program in JavaScript - JavaScript Programs
Html Html5 CSS JavaScript Ajax JQuery AngularJS JSON GMaps Adsense Blogger Earning Email Domain SEO SMO ... <!doctype html> <html> <head> <script> function palin() { var a,no,b,temp=0; no=Number(document.getElementById("no_input").value); b=no; while(no>0) { a=no; no=parseInt(no/10); temp=temp*10+a; } alert(temp); } </script> </head> <body> Enter any Number: <input id="no_input"> <button onclick="palin()">Check</button></br></br> </body> </html>
🌐
Newtum
blog.newtum.com β€Ί reverse-number-in-javascript-exploring-multiple-methods
Reverse number in Javascript - Exploring Multiple Methods - Newtum
May 14, 2024 - In conclusion, exploring the various methods to reverse number in JavaScript, including string reversal, array reduce(), string iteration, and recursion-based approaches, enhances problem-solving skills. Newtum offers a wide range of tutorials and courses in programming languages, fostering continuous learning and growth.
🌐
Just Academy
justacademy.co β€Ί index.php β€Ί blog-detail β€Ί how-to-reverse-a-number-in-javascript
How to Reverse a Number in JavaScript
Implementing a function to reverse a number in JavaScript involves iterating through the digits of the number and reconstructing them in reverse order, typically utilizing basic math operations like modulo (%) and division (/) to extract and ...
🌐
Quora
redrockwest.quora.com β€Ί How-to-reverse-a-number-using-JavaScript
How to reverse a number using JavaScript - Red Rock West - Quora
Answer: This was from a post I made on code project some time ago : [code]Reverse = function(number) { var reversed = 0; var exponent = number.indexOf('.'); if (exponent !== -1) { number *= Math.pow(10, number.length - exponent - 1); } while (number != 0) { reversed *= 10; rever...