I am using a function to check if required fields are filled. I have these two functions, that should do the same, however the first one does not. Shouldn't javascript stop executing code, after it meets a return?
This functions returns true:
//Checks if various stages are ready
function trnReady(area) {
switch (area)
{
case 'settings':
$('input.required').each(function(){
if($(this).val() == '')
{
return false;
}
});
break;
}
return true;
}
While this one returns false:
//Checks if various stages are ready
function trnReady(area) {
var r = true;
switch (area)
{
case 'settings':
$('input.required').each(function(){
if($(this).val() == '')
{
r = false;
}
});
break;
}
return r;
}
I thought the first return would stop executing code? I'm wondering if it has anything to do with scope?
return, which is the one passed to.each().