How to play a sound in JavaScript?

To play a sound in JavaScript, do this: new Audio('sound.mp3').play().

Here's how you do it:

new Audio('https://www.kozco.com/tech/piano2.wav').play();