you’re welcome. I’m not a “developer” but I do contribute to p5.js and definitely this is a confusing part of JavaScript that has to be documented.
Since everything is “asynchronous” in JavaScript except special cases, JavaScript won’t wait till song1.play()
is ended or not, and goes on to the next operation. setTimeout or addCue postpones the operation, and this is the “natural” way of coding in JavaScript. This is actually useful if you get used to it. What you suggested can be problematic in some cases - imagine you want to do some operations between song1.play()
and song2.play()
.