- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

The least common multiple, (LCM) of two integers a and b, is the smallest positive integer that is divisible by both a and b.

**For example −**

LCM of 4 and 6 is 12 because 12 is the smallest number that is exactly divisible by both 4 and 6.

We are required to write a JavaScript function that takes in two numbers, computes and returns the LCM of those numbers.

Following is the code −

const num1 = 4; const num2 = 6; const findLCM = (num1, num2) => { let hcf; for (let i = 1; i <= num1 && i <= num2; i++) { if( num1 % i == 0 && num2 % i == 0) { hcf = i; }; }; let lcm = (num1 * num2) / hcf; return lcm; }; console.log(findLCM(num1, num2));

Following is the output on console −

12

- Related Questions & Answers
- Write a program to calculate the least common multiple of two numbers JavaScript
- Finding the least common multiple of a range of numbers in JavaScript?
- Smallest Common Multiple of an array of numbers in JavaScript
- Calculating least common of a range JavaScript
- C program to find Highest Common Factor (HCF) and Least Common Multiple (LCM)
- Print the kth common factor of two numbers
- Java program to calculate the product of two numbers
- Checking if decimals share at least two common 1 bits in JavaScript
- C++ Program for the Common Divisors of Two Numbers?
- PHP program to calculate the repeated subtraction of two numbers
- Common element with least index sum in JavaScript
- C++ Program for Common Divisors of Two Numbers?
- Python Program for Common Divisors of Two Numbers
- Java Program for Common Divisors of Two Numbers
- Count common prime factors of two numbers in C++

Advertisements