you can check by this.
var fileFormat = "mp3";
var mp3Test = new Audio();
var canPlayMP3 = (typeof mp3Test.canPlayType === "function" && mp3Test.canPlayType("audio/mpeg") !== "");
if (!canPlayMP3) {
fileFormat = "ogg";
}
var sound = new Audio('sound/test.' + fileFormat);
sound.play();
<audio>
<source src="test.mp3" type='audio/mpeg; codecs="mp3"'>
<source src="test.ogg" type='audio/ogg; codecs="vorbis"'>
</audio>