• Calculates the absolute difference between two numbers.

    Parameters

    • a: number

      The first number.

    • b: number

      The second number.

    Returns number

    The absolute difference between a and b.

    // Calculate the distance between two points on a number line.
    const point1 = 5;
    const point2 = 8;
    const result = distance(point1, point2);
    // result is 3

    // Calculate the absolute difference between two values.
    const value1 = -10;
    const value2 = 20;
    const result2 = distance(value1, value2);
    // result2 is 30
MMNEPVFCICPMFPCPTTAAATR