If a position in format [x, y, z] is provided for both arguments, distance also checks the z dimension as well. Ie:
player distance [0,0,200]
will return 200, if the player is at this position at ground/sea level.

When objects are supplied as arguments, distance is calculated from their model center (object modelToWorld [0,0,0]), and not the position returned by getPos/ATL/ASL.
However, this is not relevant for units, as their model center matches their world position.