Your equipment dictates which punch in of audio cable to use.
Both types transfer a digital audio signal from one gear to the other.
Possible radio frequency or electromagnetic interference.

Lifewire / Tim Liedtke
No radio or electromagnetic frequency interference.
Not all audio devices support both coaxial and optical cables, so you may not have a choice.
If you do have a choice, it still may not matter much.
Many experts say the difference in audio quality and performance is negligible.
That being said, it’s a good idea to learn the basics about coaxial and optical cable connections.
Sturdy, harder to detach from inputs.
Cannot carry many high-quality lossless audio formats.
Coaxial cables look and operate much like traditionalRCA jacks, which are favored for their ruggedness and durability.
They may be susceptible to radio frequency interference (RFI) or electromagnetic interference (EMI).
If any existinghumming or buzzingis present within a system, a coaxial cable may transfer that noise between components.
However, if distance is an issue, then optical cables are the better choice.
Less sturdy, more easily detached.
Optical or “Toslink” cables use light to transfer audio through optical fibers.
Audio signals must be converted from an electrical signal to an optical one before traveling through the cable.
Once the converted signal reaches the receiver, it is converted back into an electrical signal.
HDMI cablestransfer both audio and video.
If your equipment supports HDMI connections, you should use it.