`console.log(Math.floor(100000 + Math.random() * 900000));`

Will always create a number of 6 digits and it ensures the first digit will never be 0. The code in your question *will* create a number of less than 6 digits.

### Related Contents:

- Get a random number focused on center
- Generate unique random numbers between 1 and 100
- Generate random string/characters in JavaScript
- Generate random number between two numbers in JavaScript
- Get a random item from a JavaScript array [duplicate]
- How to sort an array of integers correctly
- Can I hide the HTML5 number input’s spin box?
- How do I check that a number is float or integer?
- Random color generator
- How do I convert an integer to binary in JavaScript?
- Check if a number has a decimal place/is a whole number
- Remove insignificant trailing zeros from a number?
- Add st, nd, rd and th (ordinal) suffix to a number
- JS generate random boolean
- Testing whether a value is odd or even
- Why is it that parseInt(8,3) == NaN and parseInt(16,3) == 1?
- Seedable JavaScript random number generator
- How to sort numbers correctly with Array.sort()? [duplicate]
- How random is JavaScript’s Math.random?
- Javascript Thousand Separator / string format [duplicate]
- Convert long number into abbreviated string in JavaScript, with a special shortness requirement
- Elegant method to generate array of random dates within two dates
- Number.sign() in javascript
- Evaluating a string as a mathematical expression in JavaScript
- How can I use JavaScript to limit a number between a min/max value?
- How do you set, clear and toggle a single bit in JavaScript?
- JavaScript string and number conversion
- How to format a number with commas as thousands separators?
- add commas to a number in jQuery
- Why does JavaScript handle the plus and minus operators between strings and numbers differently?
- Simplest way of getting the number of decimals in a number in JavaScript [duplicate]
- JavaScript adding decimal numbers issue [duplicate]
- JavaScript expression to generate a 5-digit number in every case
- Confusion between isNaN and Number.isNaN in javascript
- Show a leading zero if a number is less than 10 [duplicate]
- Format numbers in JavaScript similar to C#
- Removing value from array on specific location [duplicate]
- How to convert a String containing Scientific Notation to correct Javascript number format
- Negative numbers to binary string in JavaScript
- how to display a javascript var in html body
- How do I round a number in JavaScript?
- JavaScript Random Positive or Negative Number
- HTML input type=”number” still returning a string when accessed from javascript
- Is Math.random() cryptographically secure?
- Javascript: How to retrieve the number of decimals of a *string* number?
- JavaScript: Get the second digit from a number?
- How to decide between two numbers randomly using javascript?
- Best way to generate a random color in javascript? [closed]
- JavaScript numbers to Words
- How does “+var === +var” work internally to verify if var is numeric?