- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Returning number of digits in factorial of a number in JavaScript
Problem
We are required to write a JavaScript function that takes in a number, num, as the first and the only argument.
Our function should compute and return the number of digits in the factorial of the number num.
For example, if the input to the function is −
Input
const num = 7;
Output
const output = 4;
Output Explanation
Because the value of 7! Is 5040 which contains 4 digits.
Example
Following is the code −
const num = 7; const countDigits = (num = 1) => { let res = 0; while(num >= 2){ res += Math.log10(num); num--; }; return ~~res + 1; } console.log(countDigits(num));
Output
4
- Related Articles
- Returning number with increasing digits. in JavaScript
- Find sum of digits in factorial of a number in C++
- Returning the expanded form of a number in JavaScript
- Function to compute factorial of a number in JavaScript
- Separating digits of a number in JavaScript
- Digit sum upto a number of digits of a number in JavaScript
- Prime digits sum of a number in JavaScript
- Recursively adding digits of a number in JavaScript
- Reversing the bits of a decimal number and returning new decimal number in JavaScript
- Returning a range or a number that specifies the square root of a number in JavaScript
- Finding product of Number digits in JavaScript
- Number of digits that divide the complete number in JavaScript
- Calculating a number from its factorial in JavaScript
- Factorial of a large number
- Product sum difference of digits of a number in JavaScript

Advertisements