How to print numbers from 1 to 100 in JavaScript

To write numbers from 1 to 100 using JavaScript, you can use a loop, such as a for loop. Here's an example of how you can do this:

for (let i = 1; i <= 100; i++) { console.log(i); }

In this code:

  • We are initializing a variable i to 1. This variable will keep track of the current number.
  • The for loop will continue as long as i is less than or equal to 100 and will be giving the output up to 100..
  • Inside the loop, we use console.log(i) to print the value of i to the console, here you can use any of the html element.

When you run this code, it will print numbers from 1 to 100, one number per line, in your browser's developer console.

You can modify the loop or use the numbers in any way you need for your JavaScript application.

Previous Post Next Post