How can I exit from a javascript function?
javascript, jquery
Solution
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.
Problem
I have the following: ``` function refreshGrid(entity) { var store = window.localStorage; var partitionKey; ... ... ``` I would like to exit from this function if an "if" condition is met. How can I exit? Can I just say break, exit or return?