Parameters to functions are always optional. You can call it
let result =
GOOGLEMAPS_DISTANCE(origin1, destination1, mode1, waypoints1)
Or
let results = GOOGLEMAPS_DISTANCE(origin2, destination2, mode2)
in which case inside the function wayponts = undefined.
However optional parameter start from the end of the parameter list so there is no way to make destination optional but mode required. In that case you have to include a null in the parameter list
let result = GOOGLEMAPS_DISTANCE (origin3, null, mode3, waypoints3)