I have seen some developers place a return at the end of their JavaScript functions like this:
$(".items").each(function(){
mthis = $(this);
var xposition = some .x() position value;
if(xposition < 0){
mthis.remove();
return;
}
});
Is having a return even necessary? I know that return false
cancels out of a loop early and I know that return x
, returns a value, but having just return??? What does that mean?
Sorry - I forgot to put an end } at the very end of the code. the return is in the if conditional.
New Update - just discovered that the intent of the loop was to cancel out the nth .item that entered the loop. so return false is my replacement for a simple return; (which means undefined anyway). Thanks everyone for the help!