## 📋 Table Of Content

In this short post, we will write a function to convert kilometers (km) to miles (mi) using JavaScript.

We know that 1 kilometer = 0.621371 miles, so we can use a simple formula of multiplying the kilometer value by 0.621371 to get miles.

The distance in miles is equal to the distance in kilometers multipled by 0.6211371

``````miles = kilometers * 0.621371
``````

Here, 0.621371 is the conversion factor.

## JavaScript Program to convert Kilometers to Miles

``````const kilometers = 25;

// formula convert kilometers to miles
const miles = kilometers * 0.621371

console.log(`\${kilometers} kilometers = \${miles} miles.`);
``````

Output:

``````25 kilometers = 15.534275000000001 miles.
``````

Here, we have checked how many miles is 25km using the formula `kilometers * 0.621371`. And the result is 15.534275000000001 miles.

If you want to convert miles to kilometers, then we use the formula,

``````kilometers = miles / 0.621371
``````

Conclusion:

To convert kilometers (km) to miles (mi), we have to multiply the kilometer value by 0.621371.

Related Topics:

Convert seconds to minutes and seconds (mm:ss) using JavaScript

JavaScript - Convert Days to Seconds

Convert a Unix timestamp to time in JavaScript

Convert date to long date format using Javascript