how to print 1 to 10 table in javascript

To print a table of numbers from 1 to 10 in JavaScript, you can use a for loop to iterate over the numbers and print the values using the console.log method. Here are a few examples of different ways to print a table of numbers from 1 to 10:

Example 1: Using a for loop and multiple console.log statements

how to print 1 to 10 table in javascript
how to print 1 to 10 table in javascript

Example 2: Using a for loop and nested for loop

how to print 1 to 10 table in javascript
how to print 1 to 10 table in javascript

In both examples, the outer for loop starts by declaring a variable i and setting its value to 1. The loop then continues to run as long as i is less than or equal to 10. On each iteration of the loop, the i variable is incremented by 1.

In Example 1, the console.log method is used to print the values of the multiplication table for each value of i. The expression i * j calculates the product of i and j, and the expression i + ” * ” + j + ” = ” + (i * j) concatenates the values of i, ” * “, j, ” = “, and the product of i and j to create a string. This string is then passed to the console.log method to be printed.

In Example 2, the inner for loop starts by declaring a variable j and setting its value to 1. The inner loop then continues to run as long as j is less than or equal to 10. On each iteration of the inner loop, the j variable is incremented by 1. The console.log method is used to print the values of the multiplication table for each value of j.

Both examples will output a table of the multiplication of the numbers from 1 to 10:

how to print 1 to 10 table in javascript
how to print 1 to 10 table in javascript

By umarbwn