In electronics, a diode is a two-terminal electronic component that conducts primarily in one direction (asymmetric conductance); it has low (ideally zero) resistance to the flow of current in one direction, and high (ideally infinite) resistance in the other.
The contacting surface of P- and N-type semiconductors is a P-N junction.
When P-type and N-type come into contact, carriers, which are holes and free electrons, are attracted to each other, recombine at the junction of P-type and N-type, and disappear.
Because there are no carriers near the junction, it is called a depletion layer, and it becomes the same state as an insulator.
When voltage is applied by connecting P-type to "+" electrode and N-type to "-" electrode, electrons flow from N-type region to P-type region, electrons that did not disappear through recombination with holes move to “+” electrode, and current flows.
The same mechanism applies to holes in P-type region.