A nucleophilic substitution reaction is an organic process in which one nucleophile is substituted by another.
The nucleophile is an ambient nucleophile, meaning it can form bonds with both Carbon and Nitrogen atoms.
Haloalkanes are open-chain hydrocarbons in which one or more than one hydrocarbon is replaced by halogen.
Because KCN is an ionic molecule, both Carbon and Nitrogen sides are available for bond formation, but the bond is stronger than the bond, resulting in cyanide production.
General representation of reaction is
Example:
Therefore, Haloalkanes on reacting with gives Alkyl Cyanide