How to use Multiplication Assignment Operator In Javascript
When multiplying a variable by a specific amount and returning the result to the variable, the multiplication assignment operator *= is a useful shorthand. In JavaScript, it is a compound assignment operator.
Example:
P = 10
P *= 2 is equal to P = P*2
So, now P will be 20.
Syntax:
varibale_name *= value/anotherVariable_name;
Example: This example is describing how we can multiply two number using multiplication assignment operator.
Javascript
// Creating a variable having value 20 let a = 20; // Using multiplication assignment operator // Using value for multiplication a *= 10; // Printing the result console.log(a); // 10 // Using another variable for mulitiplication let b = 2; a *= b; // Printing the result console.log(a); // 10 |
200 400
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