
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Difference between a number and its reversed number JavaScript
We are required to write a JavaScript function that takes in a number as the first and the only argument.
The function should −
- calculate the reversed number for the argument.
- return the absolute difference between the original number and the reversed number.
For example −
If the input number is −
const num = 45467;
Then the reversed number will be − 76454
And the output should be 76454 - 45467 = 30987
Example
const num = 45467; const findReversed = (num, res = 0) => { if(num){ return findReversed(Math.floor(num / 10), (res * 10) + (num % 10)); }; return res; }; const findDifference = num => { const reversed = findReversed(num); const difference = Math.abs(num - reversed); return difference; }; console.log(findDifference(num));
Output
And the output in the console will be−
30987
- Related Articles
- Is the reversed number a prime number in JavaScript
- Maximum difference between a number JavaScript
- Convert number to reversed array of digits JavaScript
- Reversed array of digits from number using JavaScript
- Convert number to a reversed array of digits in JavaScript
- Difference between product and sum of digits of a number in JavaScript
- A number has two digit whose sum is 9.If 27 is added to the number its digits are reversed. Find the number.
- What is the difference between parseInt(string) and Number(string) in JavaScript?
- What is the difference between numeral and a number?
- Find the difference between the number 738 and that obtained on reversing its digits
- Calculating a number from its factorial in JavaScript
- A two-digit number is 4 times the sum of its digits. If 18 is added to the number, the digits are reversed. Find the number.
- Corner digit number difference - JavaScript
- Program to find maximum difference of any number and its next smaller number in Python
- Return the difference between the maximum & minimum number formed out of the number n in JavaScript

Advertisements