- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing

- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM

- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers

- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources

# How to get the product of two integers without using * JavaScript

We are required to write a function that takes in two numbers and returns their product, but without using the (*) operator.

## Trick 1: Using Divide Operator Twice

We know that multiplication and division are just the inverse of each other, so if we divide a number by other number’s inverse, won’t it be same as multiplying the two numbers?

Let’s see the code for this −

const a = 20, b = 45; const product = (a, b) => a / (1 / b); console.log(product(a, b));

## Trick 2: Using Logarithms

Let’s examine the properties of logarithms first −

log(a) + log(b) = log(ab)

So, let’s use this property of logarithms to our good. The code for this will be −

## Example

const a = 20, b = 45; const product = (a, b) => { const logProduct = Math.log(a) + Math.log(b); return Math.round(Math.exp(logProduct)); }; console.log(product(a, b));

## Output

The output in the console for both will be −

900

- Related Articles
- How to find the binomial coefficient of two integers using JavaScript?
- How to sum two integers without using arithmetic operators in C/C++?
- How to sum two integers without using arithmetic operators in C/C++ Program?
- Maximum Product of Two Numbers in a List of Integers in JavaScript
- Product of two number using HOC - JavaScript
- Divide two integers without using multiplication, division and mod operator
- How to get almost increasing sequence of integers in JavaScript ?
- Subtracting two numbers without using the (-) sign JavaScript
- How to find the product of two binary numbers using C#?
- How to get the code name and product name of the browser in JavaScript?
- Get the Kronecker product of two arrays in Python
- Get the Outer product of two arrays in Python
- Get the Inner product of two arrays in Python
- Prove that the product of two consecutive positive integers is divisible by 2.
- The product of two consecutive positive integers is $306$. Form the quadratic equation to find the integers, if $x$ denotes the smaller integer.

Advertisements