How to use for Loop In Javascript

We can multiply two numbers by using for loop. A function must first be initialized before multiplication calculations can be made using a for loop.

Syntax:

for (initialization ; condition ; iteration) {
    // Code to be executed in each iteration
}

Example: This examples describes how we can multiply two numbers using for loop

Javascript




// Function for multiplication
function multiply(a, b) {
    let result = 0;
    for (let i = 1; i <= b; i++) {
        result += a;
    }
    return result;
}
  
// Calling function and storing the returned value
let result = multiply(5, 10); // 50
  
// Display the result
console.log(result);


Output

50


JavaScript Program for Multiplication of Two Numbers

In this article, we are going to learn how we can multiply two numbers using JavaScript. Multiplying the two numbers in JavaScript involves performing arithmetic addition on numeric values, resulting in their sum.

JavaScript supports numeric data types. In JavaScript, both floating-point and integer numbers fall under the same “Number” type. Because JavaScript takes care of it for you, you don’t need to explicitly declare whether a number is an integer or a floating-point number. In order to avoid having to declare them separately, we can use a variable and assign it to any value.

Examples:

Let's take two numbers 
a = 4 , b = 10
 
Here a is multiplicand and  b is multiplier 
a * b = 4 * 10 = 40

These are the following ways by which we can multiply two numbers:

Table of Content

  • Using “*” Operator
  • Using Functions
  • Using Arrow function
  • Using Multiplication assignment operator
  • Using for loop

Similar Reads

Using “*” Operator

...

Using Functions

In this approach we multiply two numbers in JavaScript involves using the * operator to perform arithmetic multiplication on numeric variables, resulting in their result....

Using Arrow function

...

Using Multiplication Assignment Operator

Functions are the building blocks of some specific code that carry out specific tasks. Using the function, we can multiply two numbers by passing parameters, and the function will then return the result of the multiplication....

Using for Loop

...

Contact Us