How can I exit from a javascript function? [duplicate]
if ( condition ) {
return;
}
The return
exits the function returning undefined
.
The exit
statement doesn't exist in javascript.
The break
statement allows you to exit a loop, not a function. For example:
var i = 0;
while ( i < 10 ) {
i++;
if ( i === 5 ) {
break;
}
}
This also works with the for
and the switch
loops.
Use return statement anywhere you want to exit from function.
if(somecondtion)
return;
if(somecondtion)
return false;
you can use
return false;
or return;
within your condition.
function refreshGrid(entity) {
var store = window.localStorage;
var partitionKey;
....
if(some_condition) {
return false;
}
}