JavaScript: Get the distance between two given points
JavaScript fundamental (ES6 Syntax): Exercise-243 with Solution
Distance Between Points
Write a JavaScript program to get the distance between two given points.
- Use Math.hypot() to calculate the Euclidean distance between two points.
Sample Solution:
JavaScript Code:
Output:
2.23606797749979 5
Flowchart:

Live Demo:
For more Practice: Solve these Related Problems:
- Write a JavaScript program that calculates the Euclidean distance between two points in a 2D plane.
- Write a JavaScript function that computes the distance between two coordinate pairs using the Pythagorean theorem.
- Write a JavaScript program that returns the Manhattan distance between two points for grid-based calculations.
- Write a JavaScript function that generalizes distance calculation to 3D points using the Euclidean formula.
Improve this sample solution and post your code through Disqus
Previous: Write a JavaScript program to remove elements from the end of an array until the passed function returns true. Returns the remaining elements in the array.
Next: Write a JavaScript program to get the difference between two given arrays.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.