DeveloperBreeze

Calculate Distance Between Two Points

// Function to calculate the distance between two points in a 2D plane
function calculateDistance(x1, y1, x2, y2) {
    const deltaX = x2 - x1;
    const deltaY = y2 - y1;
    return Math.sqrt(deltaX ** 2 + deltaY ** 2);
}

// Calculate and log the distance between two points (e.g., (0, 0) and (3, 4))
const distance = calculateDistance(0, 0, 3, 4);
console.log('Distance Between Two Points:', distance);

Related Posts

More content you might like

Tutorial
javascript

Running JavaScript in the Browser Console

Modern browsers come with built-in developer tools that include a JavaScript console, a powerful environment for writing, testing, and debugging JavaScript code. In this tutorial, we’ll learn how to access and use the console.

  • Quick Testing: Test snippets of JavaScript code without setting up a development environment.
  • Debugging: Check errors and log values during code execution.
  • Real-Time Interaction: Manipulate and inspect web page elements dynamically.

Dec 10, 2024
Read More
Tutorial
javascript

Mastering console.log Advanced Usages and Techniques

Placeholders:

  • %s: String
  • %d or %i: Integer
  • %f: Floating-point number
  • %o: Object
  • %c: CSS styles

Sep 02, 2024
Read More
Code
javascript

Parse JSON String to Object

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Validate Password Strength

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!