Proper way to wait for one function to finish before continuing?

I have two JS functions. One calls the other. Within the calling function, I’d like to call the other, wait for that function to finish, then continue on. So, for example/pseudo code: function firstFunction(){ for(i=0;i<x;i++){ // do something } }; function secondFunction(){ firstFunction() // now wait for firstFunction to finish… // do something else }; … Read more