Sat Apr 22 2023
Speed conversion in JavaScript
In todays post, we will do some speed conversion between three units, km/h, mph and m/s.
In order to solve this, we have a conversion factor that we will use to convert each unit to another.
Conversion table
Below table will show each conversion factor we will use to convert the units.
Implementation
m/s to km/h
const msToKmh = (ms) => ms * 3.6; console.log(msToKmh(25)); // 90
m/s to mph
const msToMph = (ms) => ms * 2.23693629; console.log(msToMph(17)); // ~38
mph to km/h
const mphToKmh = (mph) => mph * 1.609344; console.log(mphToKmh(60)); // ~96.5
mph to m/s
const mphToMs = (mph) => mph * 0.44704; console.log(mphToMs(55)); // ~24.5
km/h to m/s
const kmhToMs = (kmh) => kmh * 0.27777778; console.log(kmhToMs(50)); // ~13.9
km/h to mph
const kmhToMph = (kmh) => kmh * 0.621371; console.log(kmhToMph(120)); // ~74.5
Outro
In this guide, we did some conversion between the most common units that we measure speed for wind and vehicles. I hope you found this somewhat useful, and thanks for reading this post!
Have an amazing day!
Sat Apr 22 2023
See all our articles