We know that the electrostatic force is a conservative force. i.e the work done by the force in moving a test charge from one point to another is independent of the path connecting the two points.
Suppose we calculate the work done by the electric field due to a charge Q located at the origin to take a test charge q from the point A to B along the path shown.