Many people use metonymy to call a variety of devices that conceptually connect or disconnect signals and communication paths between electrical devices as "switches", analogous to the way mechanical switches connect and disconnect paths for electrons to flow between two conductors.
Other operating principles are also used (for instance, solid-state relays invented in 1971 control power circuits with no moving parts, instead using a semiconductor device to perform switching—often a silicon-controlled rectifier or triac).
The diode can be treated as switch that conducts significantly only when forward biased and is otherwise effectively disconnected (high impedance).
The bipolar junction transistor (BJT) cutoff and saturation regions of operation can respectively be treated as a closed and open switch.
The opto-isolator uses light from an LED controlled by a current which is received by a phototransistor to switch a galvanically-isolated circuit.
Electronic switches may also consist of complex configurations that are assisted by physical contact, for instance resistive or capacitive sensing touchscreens.