Question

Probably the most short question. What if I have these code and I want to stop executing any further after specific point inside jQuery document ready. Does return will do the job in any case?

$(function(){

return; //stop executing any further.

alert('passed 1');

(function(){
  alert('passed 2');
})();

check();

});

function check(){
 alert('passed 3');
}
Was it helpful?

Solution

return will stop the execution of the function in which you are calling it directly.

So yes, it will work in your case, unless you are putting it in the other two functions (check or the self-executing one) - in that case it will of course only stop the execution in the function you have put it into.

I must warn you that this is not a very good practice in most cases. Easily leads to code that is not pleasant to read and not easy to follow.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top