
- 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
Recursively adding digits of a number in JavaScript
We are required to write a JavaScript function that takes in a number and recursively adds the digits of the number until the result is not a single digit number.
For example, If the number is −
54563
Then the output should be 5, because,
= 5 + 4 + 5 + 6 + 3 = 23 = 2 + 3 = 5
Example
The code for this will be −
const num = 54563; const addRecursively = num => { if(num < 10){ return num; }; let sum = 0; while(num !== 0) { sum += (num%10); num = parseInt(num/10); }; return addRecursively(sum); }; console.log(addRecursively(num));
Output
The output in the console −
3
- Related Articles
- Reduce sum of digits recursively down to a one-digit number JavaScript
- Adding digits of a number using more than 2 methods JavaScript
- Separating digits of a number in JavaScript
- Adding one to number represented as array of digits in C++?
- Returning number of digits in factorial of a number in JavaScript
- Prime digits sum of a number in JavaScript
- Program for adding 4 hex digits of a 16-bit number in 8085 Microprocessor
- Digit sum upto a number of digits of a number in JavaScript
- Adding one to number represented as array of digits in C Program?
- Finding product of Number digits in JavaScript
- Product sum difference of digits of a number in JavaScript
- Recursive product of all digits of a number - JavaScript
- Convert number to a reversed array of digits in JavaScript
- Destructively Sum all the digits of a number in JavaScript
- Largest product of n contiguous digits of a number in JavaScript

Advertisements