The membrane surrounding an axon prevent random flowing of charges into and out of the cell because IT IS SEMI PERMEABLE.
The neuronal cell membrane contain tiny channels which allow only selected substances to move into the neuron and move out of the neuron into the surrounding medium.