The best way I can think to describe the function of a switch is to ask you to conjure the image of an old fashioned switchboard operator at a telephone exchange (you’re showing your age if you can!). In the early days of the telephone, the two handsets (caller and receiver) were connected by a dedicated cable (called a tieline).
When telephone networks were established, different telephone cables were connected via an exchange. A switchboard operator would physically connect the caller to the receiving party by plugging one line into a socket that connected to another line thus forming, for the duration of the call, a single dedicated line between the calling party and the called party.
Today, the switchboard operator has been replaced by a device called a switch. In computer networks (LAN and WAN) switches are used in a similar principle, forming virtual circuits between sending and receiving computers.